0
点赞
收藏
分享

微信扫一扫

【无标题】C语言简单的头插法

一葉_code 2022-03-11 阅读 28
链表

#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;
    }
}

举报

相关推荐

0 条评论