首页 > 其他 > 详细

测试随笔功能

时间:2019-05-26 18:27:32      阅读:83      评论:0      收藏:0      [点我收藏+]

1111

啊啊啊啊

=-、*-

#include <stdlib.h>
#include "list.h"

// 创建节点
Node* create_node(void* data)
{
    Node* node = malloc(sizeof(Node));
    node->data = data;
    node->next = NULL;
    return node;
}

// 销毁节点
void destory_node(Node* node)
{
    free(node->data);
    free(node);
}

// 创建链表
List* create_list(void)
{
    List* list = malloc(sizeof(List));
    list->head = NULL;
    list->tail = NULL;
    list->size = 0;
    return list;
}

// 销毁链表
void destory_list(List* list);
// 尾添加
void add_list(List* list,void* data)
{
    Node* node = create_node(data);
    if(0 == list->size)
    {
        list->head = node;
        list->tail = node;
    }
    else
    {
        list->tail->next = node;
        list->tail = node;
    }
    list->size++;
}

// 删除
bool del_list(List* list,void* cond,compar cmp)
{
    Node* temp = list->head;
    if(cmp(cond,list->head->data))
    {
        list->head = temp->next;
        destory_node(temp);
        list->size--;
        return true;
    }
    while(NULL!=temp->next)
    {
        if(cmp(cond,temp->next->data))
        {
            Node* node = temp->next;
            temp->next = node->next;
            if(node == list->tail)
            {
                list->tail = temp;
            }
            destory_node(node);
            list->size--;
            return true;
        }
        temp = temp->next;
    }
    return false;
}

// 查找
void* find_list(List* list,void* cond,compar cmp);
// 排序
void sort_list(List* list,compar cmp);
// 遍历
void show_list(List* list,void (*show)(void* data))
{
    for(Node* node=list->head; NULL!=node; node=node->next)
    {
        show(node->data);
    }
}

 

测试随笔功能

原文:https://www.cnblogs.com/ikaros-521/p/test.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!