#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node next;
}Node;
Node CreatList(int n)
{
Node *head,*p,end;
head=(Node)malloc(sizeof(Node));
end=head;
for(int i=0;i<n;i++)
{
p=(Node*)malloc(sizeof(Node));
scanf("%d",&p->data );
end->next=p;
end=p;
}
end->next=NULL;
return head;
}
void ShowList(Node *phead)
{
for(phead=phead->next;phead->next!=NULL;phead=phead->next)
printf("%d ",phead->data);
}
int main(void)
{
Node *phead;
int n;
scanf("%d",&n);
phead = CreatList(n);
ShowList(phead);
return 0;
}
showlist的循环判定条件错了,应该是phead!=NULL,不是phead->next!=NULL,否则最后一个不满足结果不会输出