#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
typedef int Elemtype;
typedef struct DNode{
Elemtype data;
struct DNode *prior,*next;
}DNode,*DLinkList;
DLinkList CreateList()
{
int x;
DLinkList head=(DLinkList)malloc(sizeof(DNode));
head->next=head;
head->prior=head;
scanf("%d",&x);
DNode *p=head->prior,*s;
while(x!=9999)
{
s=(DNode*)malloc(sizeof(DNode));
s->data=x;
p->next=s;
s->prior=p;
s->next=head;
head->prior=s;
p=s;
scanf("%d",&x);
}
return head;
}
void PrintDList(DLinkList L)
{
DNode *p=L->next;
while(p!=L)
{
printf("%d<---->",p->data);
p=p->next;
}
}
int main()
{
DLinkList L;
printf("请创建双向列表,输入9999表示结束\n");
L=CreateList();
PrintDList(L);
return 0;
}
|