王道数据结构–双链表
#include<bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
typedef int ElemType;
typedef struct DNode{
ElemType data;
struct DNode *prior,*next;
}DNode, *DLinklist;
bool InitDLinkList(DLinklist &L){
L = (DNode *)mallco(sizeof(DNode));
if(L==NULL) return false;
L->prior = NULL;
L->next =NULL;
return true;
}
bool InsertNextNode(DNode *p,DNode *s){
if(p==NULL||s==NULL) return false;
s->next = p->next;
if(p->next!=NULL){
p->next->prior =s;
s->prior =p;
p->next =s;
return true;
}
}
bool DeleteNextDNode(DNode *p){
if(p==NULL) return false;
DNOde *q =p->next;
if(q == NULL) return false;
p->next =q->next;
if(q->next! =NULL)
q->next->prior =p;
free(q);
}
void DestoryList(DLinkList &L){
while(L->nex!= NULL){
DeleteNextDNode(L);
}
free(L);
L=NULL;
}
bool TraverseDLinkList(DLinklist L){
if(L==NULL) return false;
DNOde *p = L;
while(p!=NULL){
p=p->next;
}
while(p!=NULL){
p=p->prior;
}
while(p->prior!=NULL){
p=p->prior;
}
return true;
}
void testDLinkList(){
DLinkList L;
InitDLinkList(L);
}