• 链表学习笔记之2


    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    //结点类型
    typedef struct student
    {
    void *data;
    struct student* next;
    }student;
    //链表类型
    typedef struct studentlist
    {
    student* head;
    student* current;
    student* tail;
    int size;
    }studentlist;

    studentlist* linked_list_construct()
    {
    studentlist* list=NULL;
    list=calloc(1,sizeof(studentlist));
    if(list==NULL)return NULL;
    return list;
    }
    void linked_list_prepend_node(studentlist *list, student *node)
    {
    if (list == NULL || node == NULL) return;
    student* head=NULL;
    head=list->head;
    if(head==NULL)
    {
    list->head=list->tail=node;
    }
    else
    {
    node->next=head;
    list->head=node;
    }
    list->size++;
    }
    void linked_list_append_node(studentlist *list, student *node)
    {
    if (list == NULL || node == NULL) return;
    student* tail=NULL;
    tail=list->tail;
    if(tail==NULL)
    {
    list->head=list->tail=node;
    }
    else
    {
    node->next=tail;
    list->tail=node;
    }
    list->size++;
    }
    student*linked_list_node_construct(const void *data)
    {
    student* node=NULL;
    node=call(1,sizeof(student));
    if(node==NULL)return NULL;
    node->data=data;
    return node;
    }
    student *linked_list_get_next_node(studentlist *list)
    {
    if (list == NULL || list->current==NULL) return NULL;
    student *node=NULL;
    node=list->current;
    list->current=list->current->next;
    return node;
    }
    void linked_list_destroy(studentlist *list)
    {
    if (list == NULL) return;
    student *node = NULL, *next = NULL;
    linked_list_seek_start(list);
    node = linked_list_get_next_node(list);
    while(node!=NULL)
    {
    next = linked_list_get_next_node(list);
    linked_list_node_destroy(node);
    node=next;
    }
    list->head = NULL;
    list->tail = NULL;
    list->current = NULL;
    list->size = 0;
    free(list);
    }
    void linked_list_remove_node(studentlist *list, student *node)
    {
    if (list == NULL || node == NULL)
    {
    return;
    }
    if (node == list->head)
    {
    list->head = node->next;
    }
    if (node == list->tail)
    {
    list->tail = list->head;
    }
    node->next = NULL;
    list->size--;
    }
    void linked_list_node_destroy(student *node)
    {
    if (node == NULL) return;
    free(node);
    }
    void linked_list_seek_start(studentlist *list)
    {
    if (list == NULL) return;
    list->current=list->head;
    }
    void linked_list_seek_end(studentlist *list)
    {
    if (list == NULL) return;
    list->current=list->tail;
    }
    int linked_list_length(studentlist *list)
    {
    if (list == NULL) return 0;
    return list->size;
    }
    int linked_list_is_empty(studentlist *list)
    {
    if (list == NULL) return 1;
    return list->head=NULL;
    }

    备注:#pragma comment(lib,"PrivateProtocol.lib") 调用静态库

  • 相关阅读:
    Postman安装与使用
    最新的爬虫工具requests-html
    从高级测试到测试开发
    uiautomator2 使用Python测试 Android应用
    zalenium 应用
    Docker Selenium
    Java 测试驱动开发--“井字游戏” 游戏实战
    DevOps/TestOps概念
    Android测试(四):Instrumented 单元测试
    appium对博客园APP进行自动化测试
  • 原文地址:https://www.cnblogs.com/fx2008/p/2206600.html
Copyright © 2020-2023  润新知