#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct DLNode{
ElemType data;
struct DLNode *next,*piror;
}DLNode,*DLinkList;
//初始化双链表
bool InitList(DLinkList &L){
L=(DLinkList)malloc(sizeof(DLNode));
if(L==NULL) return false;
L->next=NULL;
L->piror=NULL;//带头结点的双链表前驱指针piror永远是NULL
return true;
}
//双链表的判空
bool IsEmpty(DLinkList L){
if(L->next=NULL) return true;
else return false;
}
//输出双链表
void PrintDList(DLinkList L){
DLNode *p=L;
if(p->next==NULL) printf("this is an empty DList!");
else while(p->next!=NULL) {
printf("the DList is %d",p->data);
p=p->next;
}
}
//双链表的创建
bool CreateDList(DLinkList &L,ElemType x){
DLNode *p=L;
DLNode *s=(DLNode *)malloc(sizeof(DLNode));
s->data=x;
if(p->next==NULL){/* 当双向链表只有一个头结点时 */
s->next=p->next;
p->next=s;
s->piror=p;
}
else{/* 当双向链表不只一个头结点时 */
p->next->piror=s;
s->piror=p;
s->next=p->next;
p->next=s;
}
return true;
}
int main(){
DLinkList L;
for(int i=1;i<=3;i++)
CreateDList(L,i);
PrintDList(L);
return 0;
}