zoukankan      html  css  js  c++  java
  • 测试随笔功能

    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);
        }
    }
  • 相关阅读:
    Hash表的查找-C语言
    二叉排序树-C语言
    线性表的查找算法-C语言
    拓扑排序和关键路径
    图结构的创建与遍历-C语言
    MySQL数据库基本脚本命令
    哈夫曼树编码-C语言
    协程简述
    Python多线程编程-Threading库
    Python多进程编程-multiprocessing库
  • 原文地址:https://www.cnblogs.com/ikaros-521/p/test.html
Copyright © 2011-2022 走看看