c语言插入动态链表,动态链表插入结点问题,麻烦各位帮忙看一下

这段代码展示了如何使用C语言创建一个链表结构,并从用户输入中读取学生信息来构建链表。程序首先分配内存创建第一个节点,然后通过循环不断接收用户输入,直到输入的学号为0时停止。每个新节点被添加到链表的末尾,最终形成一个按学号顺序排列的学生链表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

struct student

{

long num;

float score;

struct student *next;

};

struct student *creat(void)                                 //建立链表

{

struct student *head;

struct student *p1,*p2;

p1=(struct student *)malloc(sizeof(struct student));

printf("Input the first student's information:\n");

printf("num:");

scanf("%ld",&p1->num);

printf("score:");

scanf("%f",&p1->score);

head=p1;

p2=p1;

while(p2->num!=0)

{

printf("Input next student's information:\n");

printf("If you want to end it,please input0:\n");

p1=p2;

p2=(struct student *)malloc(sizeof(struct student));

printf("num:");

scanf("%ld",&p2->num);

printf("score:");

scanf("%f",&p2->score);

p1->next=p2;

}

p2->next=NULL;

return(head);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值