#include <stdio.h>
#include <stdlib.h>
typedef struct num
{
int number;
struct num *next;
}NUM;
NUM *build (int n)
{
int i;
NUM *pt,*prept,*head;
pt=(NUM*)malloc(sizeof(NUM));
if (pt!=NULL)
{
scanf("%d",&pt->number);
head=pt;
prept=pt;
}
else
{printf("no\n");exit(0);}
for (i=1;i<n;i++)
{
pt=(NUM*)malloc(sizeof(NUM));
scanf("%d",&pt->number);
prept->next=pt;
prept=pt;
}
pt->next =NULL;
NUM *q;
q = head;
while(q)
{
if(q -> next == NULL) printf("%d",q->number);
else printf("%d ", q -> number);
q = q -> next;
}
return head;
}
int main()
{
int n, i;
scanf("%d",&n);
build(n);
return 0;
}
ps:第一次接触链表哇,格式什么的有点不规范,看着网课依葫芦画瓢写的,不过还是AC了,仅供参考!