#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;
typedef struct dlnode
{
ElemType data;
struct dlnode *prior,*next;
}DLNode,*DLinkList;
void CreateDLinkList(DLinkList &DL) //创建双向链表
{
int i,num;
DLinkList p,s;
DL = (DLNode *)malloc(sizeof(DLNode));
DL->prior = DL->next = NULL;
p = DL;
printf("请输入双向链表结点数:");
scanf("%d",&num);
for(i = 1;i <= num; i++) //顺序创建链表
{
s = (DLinkList)malloc(sizeof(DLNode));
s->data = i;
s->next = p->next;
s->prior = p;
p->next = s;
p = s;
}
}
void Traverse(DLinkList DL) //遍历
{
DLinkList p = DL->next;
while(p)
{
if(p->next)
printf("%3d <==>",p->data);
else
printf("%3d",p->data);
p = p->next;
}
}
int main()
{
DLinkList DL;
CreateDLinkList(DL);
printf("\n双向链表值为:");
Traverse(DL);
printf("\n\n\n");
system("pause");
}