双向链表的创建问题
#include<stdio.h>#include<stdlib.h>
#define len sizeof(Node)
typedef struct Node
{
int data;
struct Node *prior,*next;
}Node,*DoubleLinkList;
void InitDLLinkList(DoubleLinkList *DL)
{
*DL=(DoubleLinkList)malloc(len);
(*DL)->next=NULL;
(*DL)->prior=NULL;
}
void CreatDLLinkList(DoubleLinkList DL)
{
Node *p,*s;
p=DL;
int x,flag=1;
printf("Please input data and enter 0 end:\n");
while(flag)
{
scanf("%d",&x);
if(x!=0)
{
s=(Node *)malloc(len);
s->data=x;
p->next=s;
s->prior=p;
s->next=NULL;
p=s;
}
else
{
p->next=DL;
DL->prior=p;
flag=0;
}
}
}
void PrintDLLinkList(DoubleLinkList DL)
{
Node *p;
p=DL->next;
for(;p!=DL;p=p->next);
printf("%-3d",p->data);
printf("\n");
}
int main()
{
DoubleLinkList DL;
InitDLLinkList(&DL);
CreatDLLinkList(DL);
PrintDLLinkList(DL);
return 0;
}
输出的和输入的不一样,哪里错了??