#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct nade
{
int data;
struct nade *next;
};
int main()
{
int n,i;
struct nade *head,*tail,*p;
scanf("%d",&n);
head=(struct nade*)malloc(sizeof(struct nade));
head->next=NULL;
tail=head;
for(i=0;i<=n-1;i++)
{
p=(struct nade*)malloc(sizeof(struct nade));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
while(p)
{
if(p->next==NULL)
printf("%d\n",p->data);
else printf("%d ",p->data);
p=p->next;
}
return 0;
}
顺序建立链表
最新推荐文章于 2022-02-24 10:36:26 发布