69,382
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
struct node
{
int data;
struct node *next;
};
struct node *build()
{
int x;
struct node *head,*tail,*p;
head=tail=NULL;
printf("please input x\n");
scanf("%d",&x);
while(x!=0)
{
p=(struct node*)malloc(sizeof(struct node));
p->data=x;
p->next=NULL;
if(head==NULL)
head=tail=p;
else
{
tail->next=p;
tail=p;
}
scanf("%d",&x);
}
return head;
}
void main()
{
struct node *q;
q=build();
while(q != NULL)
{
printf("%d ",q->data);
q=q->next;
}
getchar();
}