#include<stdio.h>
#include<stdlib.h>
typedef struct student
{
int a;
struct studemt *next;
} x;//定义一个结构体
x *Create(int n)
{
x *head,node,end;//定义头节点,普通节点,尾部节点
head=NULL; 将头节点初始化
head=(x)malloc (sizeof (x));
if(head==NULL)
{
printf (“malloc fair”);
}//判断空间是否申请成功
end=head;
for (int i=0;i<n;i++)
{
node=(x)malloc(sizeof (x));
scanf("%d",&node->a);注意取地址符
end->next=node;
end=node;
}
end->next=NULL;
return head;//返回首地址
}
int main ()
{
int i;
scanf("%d",&i);//想要链表的长度
x *p;//定义一个结构体指针来接收首节点
p=Create(i);
while (p->next!=NULL)
{
p=p->next;
printf("%d",p->a);
}
return 0;
}