该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
struct node
{
struct node *next;
int data;
};
struct node *creat1(int n)
{
struct node *head,*tail,*p;
int i;
head=(struct node*)malloc(sizeof(struct node));
head->next= NULL;
printf("%d\n",head->next);
tail=head;
printf("%d\n",head->next);
//printf("%d %d",&tail,&head);
for(i=1;i<=n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
printf("1 %d\n",head->next);
scanf("%d",&p->data);
printf("2 %d\n",head->next);
p->next=NULL;
printf("3 %d\n",head->next);
tail->next=p;
printf("4 %d\n",head->next);
tail=p;
printf("5 %d\n",head->next);
}
return (head);
}
void read(struct node *p,int i)
{
int j;
struct node *rd;
rd=p;
rd=rd->next;
for(j=0;j
{
printf("%d ",rd->data);
rd=rd->next;
}
}
int main()
{
int i;
struct node *q;
scanf("%d",&i);
q=creat1(i);
read(q,i);
return 0;
}