C语言简单的尾插法
作者:互联网
#include <stdio.h>
#include <stdlib.h>
struct s{
int a;
s *next;
};
int main()
{
int n,i;
s *head,*p,*r;
scanf("%d",&n);
head=(s*)malloc(sizeof(s));
head->next=NULL;
r=head;
for(i=0;i<n;i++)
{
p=(s*)malloc(sizeof(s));
scanf("%d",&p->a);
p->next=r->next;
r->next=p;
r=p;
}
head=head->next;
while(head!=NULL)
{
printf("%d ",head->a);
head=head->next;
}
}
标签:插法,head,NULL,int,scanf,malloc,next,简单,C语言 来源: https://blog.csdn.net/weixin_62428212/article/details/123308771