鱼C论坛

 找回密码
 立即注册
查看: 1735|回复: 2

(用到链表的创建、输出、删除、添加)的一道题目

[复制链接]
发表于 2022-5-18 23:14:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
[例9.19]编程实现某班学生信息管理:学生信息包括姓名l、学号、出生日期,三门课成绩,创建一个学生信息的单向链表并输出该信息,如果班级有学生退学,根据学号删除该生信息·如果班级新进学生,根据学号将其添加到系统里.(用到链表的创建、输出、删除、添加)
代码应该如何修改 才能正确运行,或者 能写一个完整的代码吗? 谢谢大家

#include<stdio.h>
#include<stdlib.h>
struct node
{
char name[15];
int num;
struct birthday
{int year;
int month;
int day;};
struct birthday date;
float score[3];
struct node *next;
};
struct node *creat(struct node *head ,int n)
{
struct node *p, *q;
int i;
for (i=1;i<=n;i++)
{
q=(struct node *)malloc(sizeof(struct node ));
printf("Input%d姓名、学号、出生日期、三订课成绩:\n",i);
scanf("%s",q->name);
scanf("%d",&q->num);
scanf("%d%d%d",&q->date.year,&q->date.month,&q->date.day);
scanf("%f%f%f",&q->score[0],&q->score[1],&q->score[2]);
q->next=NULL;
if(head==NULL)
head=q;
else p->next=q;
p=q;
}
return (head);}
struct node *dele(struct node *head)
{
struct node *p, *q;
int x;
p=head;
printf("输入要删除的学号:\n");
scanf("%d",&x);
while(p!=NULL&&p->num!=x)
{q=p;
p=p->next;}
if(p==NULL)
printf("%d is not found!\n");
else if(p==head)
head=p->next;
else q->next=p->next;
free(p);
return(head);}
struct node *insert(struct node *head)
{ struct node *q,*p,*p1;
q= (struct node *)malloc(sizeof(struct node));
printf("Input姓名、学号、出生日期、三门课成绩:\n");
scanf("%s",q->name);
scanf("%d",&q->num);
scanf("%d%d%d",&q->date.year,&q->date.month,&q->date.day);
scanf("%f%f%f",&q->score[0],&q->score[1],&q->score[2]);
if(head==NULL)
{
q->next=NULL;
head=q;
return(head);
}
if(head->num>q->num)
{
q->next=head;
head=q;
return head;
}
p=head;
p1=head->next;
while(p1!=NULL&&p1->num<q->num)
{
p=p1;
p1=p1->next;
}
q->next=p1;
p->next=q;
return(head);}
void main()
{
struct node *creat(struct node *head,int n);
void print(struct node *head);
struct node *dele(struct node *head);
struct node *insert(struct node *head);
struct node *head=NULL;
head=creat(head,3);
print(head);
head=dele(head);
print(head);
head=insert(head);
print(head);
}

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-5-18 23:17:20 | 显示全部楼层
哇!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-5-29 20:22:34 | 显示全部楼层
看不懂,求解
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-26 22:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表