求助!!!!链表,建立链表然后输出
#include<stdio.h>#include<stdlib.h>
struct list
{
int num;
struct list *node;
};
main(void)
{
struct list *head,*p,*tail;
head=NULL;
do
{
p=(struct list *)malloc(sizeof(struct list));
if(p==NULL)
{
printf("Memonry alloc failed\n");
exit(0);
}
printf("Input num\n");
scanf("%d",&p->num);
if(p->num==0)
{
free(p);
break;
}
p->node=NULL;
if(head==NULL)
{
head=p;
tail=p;
}
else
{
tail->node=p;
tail=p;
}
}while(p->num!=0);
p=head;
while(p!=NULL);
{
printf("%d",p->num);
p=p->node;
}
printf("\n");
}