带头双向链表的结构:
带头双向链表的结构复杂但是在后面的代码实现以后会发现这种结构带来很多优势,实现反而变得简单起来。
链表的实现:
声明接口函数:
#pragam once //保证头文件只被编译一次
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
typedef int LTDateType;
typedef struct ListNode
{
//双线链表的两个指针
struct ListNode *next;
struct ListNode *prev;
LTDateType x;
}LTNode;
//链表的初始化
LTNode* ListInit();
//链表的打印
void ListPrintf(LTNode* phead);
//生成新节点
LTNode * BuyListNode(LTDateType x);
//链表的尾加
void ListPushBack(LTNode* phead,LTDateType x);
//链表的头加
void ListPushFront(LTNode* phead, LTDateType x);
//链表的尾删
void ListPopBack(LTNode* phead);
//链表的头删
void ListPopFront(LTNode* phead);
//在链表中找一节点
LTNode * ListFind(LTNode* phead, LTDateType x);
//链表在pos位置前插入节点
void ListInsert(LTNode* pos,LTDateType x);
//链表删除pos位