在链表中建立的读取函数运行时总是出错.
/*参照一下...*/
/*不带头结点的*/
typedef node* nodelink;
nodelink buildlink() /* 尾插法*/
{
datatype x;
nodelink head,s;
nodelink p2;
head=NULL;
p2=NULL;
printf("please input the link:");
scanf("%d",&x);
while(x!=0)
{s=(nodelink)malloc(sizeof(node));
s->info=x;
if (head==NULL) head=s; else p2->next=s;
p2=s;
scanf("%d",&x);
}
if(p2) p2->next=NULL;
return(head);
}
nodelink creatlink() /***头插法***/
{ nodelink head,p;
datatype x;
head=NULL;
printf("please input the link:");
scanf("%d",&x);
while(x!=0)
{ p=(nodelink)malloc(sizeof(node)) ;
p->info=x;
p->next=head;
head=p;
scanf("%d",&x);
}
return head;
}