链表相关问题(高手指教错在哪)
#include<stdio.h>#include<malloc.h>
struct node
{
int data;
struct node *next;
};
struct node * create(struct node *head)
{
struct node *news,*tail;
int value;
head=tail=NULL;
printf("请输入一个整数: ");
scanf("%d",&value);
while(value!=0)
{
news=(struct node *)malloc(sizeof(struct node));
news->data=value;
news->next=NULL;
if(head==NULL)
head=tail=news;
else
{
tail->next=news;
tail=news;
}
printf("请输入一个整数: ");
scanf("%d",&value);
return(head);
}
void output(struct node *head)
{
struct node * p;
p=head;
while(p!=NULL)
{
printf("%d\n",p->data);
p=p->next;
}
}
void main()
{ struct node *head1,*head2;
head1=head2=NULL;
head2=create(head1);
output(head2);
}