一个C语言动态链表的输入问题 求教

#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct stu)
struct stu{
int id;
char name[10];
float score;
struct stu *next;
};
int n;
struct stu *creat(void) //创造
{
struct stu *head,*p1,*p2;
n=0;
p1=p2=(struct stu *)malloc(LEN);
scanf("%d%s%f",&p1->id,&p1->name,&p1->score);
head=NULL;
while(p1->id!=0)
{
n++;
if(n1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct stu *)malloc(LEN);
scanf("%d%s%f",&p1->id,&p1->name,&p1->score);
}
p2->next=NULL;
printf("%d个单元组成的链表被创造\n",n);
return(head);
}
void print(struct stu *p) //输出
{
do{
printf("%d %s %f\n",p->id,p->name,p->score);
p=p->next;
}while(p!=NULL);
printf("\n");
}
struct stu *del(struct stu *head) //精确删除——根据id
{
struct stu *p1,*p2;int id;
p1=head;
printf(“请输入要删掉学生的id:”);
scanf("%d",&id);
if(p1->id
id) head=p1->next;
else{
while(p1->id!=id){p2=p1;p1=p1->next;}
p2->next=p1->next;
}
return head;
}
**void insert(struct stu *p1) //精确插入——根据id
{
struct stu *p2,q;int id;
p2=p1;
printf(“请输入要添加学生的id:”);
scanf("%d",&id);
while(p1->id>id){p2=p1;p1=p1->next;}
q=(struct stu )malloc(LEN);
p2->next=q;
p2=p2->next;p2->next=p1;
printf(“请输入要添加学生的姓名、成绩:”);
p2->id=id;
scanf("%s%f",&p2->name,&p2->score);
}

void main()
{
struct stu *pt;
pt=creat();
print(pt);
// pt=del(pt);
// print(pt);
insert(pt);
print(pt);
}

貌似是上面加粗insert函数有问题
[图片]在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值