typedef struct dnode
{
int data;
struct dnode *prior;
struct dnode *next;
}DNode;
DNode *createDNode(void)
{
DNode *head = NULL;
DNode *p = NULL;
DNode *q = NULL;
int n = 0;
int i = 0;
printf("\n请输入双向链表的长度:");
scanf("%d",&n);
if((head=(DNode *)malloc(sizeof(DNode)))==NULL)
{
printf("分配内存失败\n");
exit(0);
}
head->data = n;
head->prior = NULL;
head->next = NULL;
p = head;
printf("请输入这%d个整数,以q结束:\n",n);
for(i=0; i {
if((q=(DNode *)malloc(sizeof(DNode)))==NULL)
{
printf("分配内存失败\n");
exit(0);
}
scanf("%d\n",&(q->data));
q->next = NULL;
p->next = q;
q->prior = p;
p = q;
}
p->next = NULL;
p->prior = NULL;
return head;
}
阅读(899) | 评论(0) | 转发(0) |