zoukankan      html  css  js  c++  java
  • 链表学习笔记之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") 调用静态库

  • 相关阅读:
    Apache的Thrift引发的编译思考
    QQ的小秘密
    快速简化Android截屏工作
    Solution of wireless link "PCI unknown" on Centos 7.1
    Java Date Compare
    eclipse集成tomcat日志文件输出配置
    身份证号码验证正则表达式
    curl用法一例 传递代理用户名密码
    HTML 5 placeHolder
    JavaScript(ECMAScript) with 语句
  • 原文地址:https://www.cnblogs.com/fx2008/p/2206600.html
Copyright © 2011-2022 走看看