1.头文件及类型定义
#include<stdio.h>
#include<stdlib.h>
#define ElemType int
2.双链表结点类型定义
typedef struct DNode {
ElemType data;
struct DNode* prior, * next;
}DNode, * DLinkList;
3.函数声明
DLinkList InitDLinkList(DLinkList& L);
bool Empty(DLinkList L);
DNode* GetElem(DLinkList L, int i);
DNode* LocateElem(DLinkList L, ElemType e);
bool InsertNextDNode1(DNode* p, DNode* s);
bool InsertNextDNode2(DNode* p, ElemType e);
bool InsertPriorDNode(DNode* p, DNode* s);
bool InsertDLinkList(DLinkList& L, int i, ElemType e);
bool DeleteNextDNode(DNode* p);
DLinkList List_HeadInsert(DLinkList& L);
void DestoryList(DLinkList& L);
int Length(DLinkList L);
void PrintDLinkList(DLinkList L);
4.基本操作
4.1 初始化双链表
DLinkList InitDLinkList(DLinkList& L) {
L = (DNode*)malloc(sizeof(DNode));
if (L == NULL)
return NULL;
L->prior = NULL;
L->next = NULL;
return L;
}
4.2 判空
bool Empty(DLinkList L) {
return (L->next == Null);
}
4.3 查找操作
4.3.1 按位查找
DNode* GetElem(DLinkList