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