394210耀智课程设计说明书.docx
《394210耀智课程设计说明书.docx》由会员分享,可在线阅读,更多相关《394210耀智课程设计说明书.docx(53页珍藏版)》请在冰豆网上搜索。
394210耀智课程设计说明书
课程设计说明书
设计名称:
程序设计语言强化课程设计
题目:
图书信息管理系统设计
学生姓名:
吕耀智
专业:
网络工程
班级:
07网络工程2
学号:
2007394210
指导教师:
周燕
日期:
2009年3月23日
课程设计任务书
网络工程专业07年级2班吕耀智
一、设计题目
(1)学生成绩排名
(2)根据条件进行学生成绩排名
(3)链表的操作(链表的建立,访问,删除链表指定结点,增加结点)
(4)学生成绩文件管理
(5)一个综合系统(图书信息管理系统)
二、主要内容
(一)学生成绩排名
先采用选择法,将学生成绩从高到低进行排序,再输入一个学生的成绩,将此成绩按照排序规律插入已排好序的学生成绩数组,最后将排好序的成绩单进行反序存放。
(二)根据条件进行学生成绩排名
在函数中进行10个学生成绩从高到低排名,再改进函数,进行n个学生成绩从高到低排名,排名方式根据函数的style参数进行,如style为‘a'按升序排,style为'd'按降序排(a:
ascending升,d:
descending降)。
编写多个不同函数,使之能实现不同的排序算法(3种以上),再编写一个通用输出函数,(要求用函数指针做参数)能分别打印不同排序算法的结果。
(三)链表的操作(链表的建立,访问,删除链表指定结点,增加结点)
建立一个动态链表,将学生数据(学号,成绩)存入链表结构中,实现链表的访问(求学生成绩的平均分,找到最高分,最低分,将其数据输出)。
删除指定学号的学生数据,对学生数据进行排序,分别在链表头部,中间,末尾插入学生数据。
(四)学生成绩文件管理
定义一个结构体数组,存放10个学生的学号,姓名,三门课的成绩,输出单门课成绩最高的学生的学号、姓名、以及该门课程的成绩,输出三门课程的平均分数最高的学生的学号、姓名及其平均分,将10个学生的相关数据,存入文件中,再从文件中读出,按照平均分数从高到低进行排序,分别将结果输出到屏幕上和另一文件中,再从文件中读取第1,3,5,7,9个学生的数据。
(五)图书信息管理系统设计:
图书信息包括:
登录号、书名、作者名、分类号、出版单位、出版时间、价格等。
试设计一图书信息管理系统,使之能提供以下功能:
(1)系统以菜单方式工作。
?
(2)图书信息录入功能--输入。
(3)图书信息浏览功能--输出。
(4)查询和排序功能:
(至少一种查询方式)--算法。
按书名查询
按作者名查询
(5)图书信息的删除与修改。
三、具体要求
围绕课程设计的目的和意义,基本要求如下:
1、认真阅读《C语言课程设计》指导书,明确课程设计的目的、意义和要求;
2、快速总结C程序设计语言的精髓,如:
函数的概念、函数的设计和函数的调用;
3、快速熟悉TuberC或C++的上机环境。
能熟练进行高级编辑操作(特别是字块操作);熟悉步进式、断点跟踪的程序调试方法,提高工作效率。
4、根据“课程设计题目”,采用结构化的程序设计思想,确定系统的总体设计方案、确"定时间进度。
如果是多人共一题,则要首先完成小组内的人员分工及安排,不允许重题现象。
5.学习并了解良好的程序设计风格。
按质、按量、并按时间完成课程设计的任务。
6.提供可运行的课程设计系统,参加上机面试答辩。
本次课程设计的重点是:
学会设计并编写函数,掌握好各函数之间的调用关系;利用文件操作函数,建立数据库并完成对数据库的各种操作;掌握几种典型算法的应用(如:
冒泡法、选择排序法和折半查找法)。
同时锻炼学生根据题目进行分析、设计、编码、调试程序和书写必要文档的综合处理能力,从实践中学习并体会程序设计的结构化思想和设计方法。
四、进度安排
依照教学计划,课程设计时间为3周。
按照软件工程的思想,软件系统的分析设计至关重要,并要充分重视书写“文档”。
避免甚至杜绝“拿到题目就编码”的现象。
建议将时间分为三个阶段:
第一阶段,根据题目要求,拿出系统的总体设计方案:
即构思各程序模块的算法,并画出相应的N-S图,同时编写相应的文档;
第二阶段,根据N-S图编写程序代码并单独调试,再将调试通过的各个子模块进行集成调试;
第三阶段,归纳文档资料,按要求填写在《课程设计说明书》上,并参加答辩。
三个阶段时间分配的大概比例是:
35:
45:
20。
五、完成后应上交的材料
1.课程设计的题目、系统的总功能和各子模块的功能;
2.题目的设计思想(或算法)简述;
3.主要程序的框图(要求用N-S图);
4.源程序代码(要求在关键的位置有注释,从而增加程序的可读性);
5.课程设计的总结报告,主要包括以下内容:
(1)课程设计中遇到的主要问题和解决方法;
(2)你的创新和得意之处;
(3)设计中存在的不足及改进的设想;
(4)本次课程设计的感想和心得体会。
以上完成的源程序及相关文档,填写在《课程设计说明书》上,要求干净整洁,符合课程设计的要求和规范。
六、总评成绩
指导教师签名日期年月日
系主任审核日期年月日
一、设计任务的主要算法分析……………………………………………1
1.1主要算法具体分析………………………………………………2
二、程序的流程图…………………………………………………………3
2.1学生成绩排名……………………………………………………3
2.2根据条件进行学生成绩排名……………………………………4
2.3链表的操作………………………………………………………7
2.4学生成绩文件管理………………………………………………7
2.5图书信息管理系统的N-S图……………………………………8
1.系统总流程图模块…………………………………………8
2.录入功能模块………………………………………………9
3.浏览功能模块…………………………………………10
4.查询功能模块………………………………………………11
5.排序功能模块…………………………………………12
6.删除功能模块………………………………………13
7.修改功能模块……………………………………………14
8.文件保存功能模块………………………………………14
三、各个模块的源代码…………………………………………………15
3.1学生成绩排名…………………………………………………15
3.2根据条件进行学生成绩排名……………………………………17
3.3链表的操作………………………………………………………22
3.4学生成绩文件管理………………………………………………32
3.5图书信息管理系统………………………………………………39
A.主函数………………………………………………………39
B.口令功能模块………………………………………………39
C.菜单功能模块………………………………………………40
D.录入功能模块………………………………………………41
E.文件保存模块………………………………………………43
F.浏览功能模块…………………………………………………44
H.查询功能模块…………………………………………………45
I.排序功能模块…………………………………………………48
J.修改功能模块…………………………………………………50
K.删除功能模块…………………………………………………52
四、程序运行效果图……………………………………………………54
4.1用户登陆画面………………………………………………54
4.2菜单功能模块………………………………………………55
4.3录入功能图示………………………………………………56
4.4浏览功能图示………………………………………………56
4.5查询功能图示………………………………………………57
4.6排序功能图示…………………………………………………58
4.7修改功能图示…………………………………………………58
4.8删除功能图示…………………………………………………59
五、设计心得…………………………………………………………60
5.1课程设计中遇到的主要问题和解决方法…………………60
5.2本程序的创新和得意之处…………………………………60
5.3设计中存在的不足及改进的设想…………………………60
5.4本次课程设计的感想和心得体会…………………………60
一.算法分析
初始化:
建立空链表
录入:
录入图书信息到链表
浏览:
向屏幕输出图书信息(就是读出函数)
查询:
按书名或作者名查找图书
删除:
删除图书信息
排序:
按照书名排序
保存:
把链表记录保存成文件
退出:
退出程序
定义图书信息的结构体如下:
structlibrary
{
longnum;
charbookname[20];
charauthor[20];
chartype[20];
charpublishing_house[20];
charpublishing_time[20];
floatsale;
structlibrary*next;
};
算法分析:
这个图书室信息系统主要是一个以动态链表的应用为基础加上C的基础语法一起的一个综合系统程序。
1主程序是用switch函数做为一个功能的选择函
2录入函数是一个建立动态链表的应用
3浏览函数是一个输出动态链表的应用
3查询函数是一个在链表中应用到各种“找值”函数的程序,例如按作者名或者书名找图书信息的话就要用字符串查找算法等等。
4删除函数是一个链表的一个指针的变化程序利用指针的作用去“删除”(不再指向)掉我们不需要的信息和“插入”(指向)我们需要的信息。
5排序函数和删除函数其实是原理是差不多,都是利用了指针的指向作用,把指向第二结构体的指针指向第一个,把第一个的指针指向第二个,那么两个结构体里面的位置就掉换了,就是我们所说排序。
6保存文件函数是把链表中的信息保存起来。
7退出程序函数是结束这个程序.
二.程序的流程图
2.1学生成绩排名
2.2根据条件进行学生成绩排名
输入成绩的学生数m
i=0;
输入m个学生的成绩b[i]
i选择排序算法k:A:选择法升序、B:选择法降序、C:冒泡法升序、D:冒泡法降序调用函数sort(b,m,k);i=0;输出b[i]i2.3链表的操作 2.5总流程图说明:这个基本是口令和菜单的结合体,用户先同过口令,3次自己关闭,用个IF就可以了,接着是接受功能键选择,根据SWITCH选择菜单里面我们需要的功能。0功能键是退出系统 2.5.1录入函数(creat)说明:这个函数把指针p1.p2指向新开的空间,然后再向空间里面写如数据,进而做成我们所需要的链表。 2.5.2浏览函数(out)说明:和录入函数差不多也是把P1指向新开的空间,不过不同的这次是从文件里面读入已经保存的数据。不是录入数据。 2.5.3查询函数(check)说明:先是用字符串比较函数STRCMP去找用户选择的查询方式,然后再用一个STRCMP一步一步在链表中再出信息,没有则退出。 2.5.4排序函数(score)说明:用字符串比较函数比较两个书名之间的大小,小在前,大在后。如果条件成立则交换结构体里面的数据。外面用选择循环就可以全部排序。 2.5.5删除函数(del)说明:利用指针的指向性,当STRCMP函数=0时找到要删除的图书信息时,把指向这个信息结构体的指针指向下一个结构体,把这个信息挡在链表外面。P2-》NEXT=P1》NEXT。 2.5.6修改函数(correct)说明:用STRCMP函数找到需要修改的书名,然后找到修改的类型,再输如修改后的信息。2.5.7文件保存函数(save)说明:用fwrite函数写入文件,当p->next!=0时一个一个吧数据写入文件知道p=NULL为止。 三.原代码程序3.1学生成绩排名#includevoidmain()/*这是主函数*/{inta[11],i,j,t;printf("请输入10个学生的成绩\n");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("10个学生的成绩从高到低排列的顺序为\n");/*10个学生成绩排列代码*/for(i=0;i<10;i++){for(j=i+1;j<10;j++){if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n请再输入一个学生的成绩\n");scanf("%d",&a[10]);printf("11个学生的成绩从高到低排列的顺序为\n");/*11个学生成绩排列代码*/for(i=0;i<11;i++){for(j=i+1;j<11;j++){if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n11个学生成绩的反序排列为\n");/*11个学生成绩的反序排列代码*/for(i=0;i<=5;i++){t=a[i];a[i]=a[10-i];a[10-i]=t;}for(i=0;i<11;i++){printf("%d",a[i]);}printf("\n");}3.2根据条件进行学生成绩排名#includevoidmain()/*这是主的函数*/{int*sort1(inta[],intn);int*sort2(inta[],intn);int*sort3(inta[],intn);int*sort4(inta[],intn);intshow(intx[],inty,int(*(*fun)(inta[],intn)));intsort(inta[],intn,charstyle);intb[100],i,m;charc1;printf("要输入成绩的学生数n\n");scanf("%d",&m);printf("请输入%d个学生的成绩\n",m);for(i=0;i{scanf("%d",&b[i]);}printf("请选择排练方式\na:选择升序法\nd:选择降序法\nA:冒泡升序法\nD:冒泡降序法\n");scanf("%s",&c1);sort(b,m,c1);printf("%d个学生成绩排列后的顺序\n",m);for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
选择排序算法k:
A:
选择法升序、B:
选择法降序、C:
冒泡法升序、D:
冒泡法降序
调用函数sort(b,m,k);
输出b[i]
i2.3链表的操作 2.5总流程图说明:这个基本是口令和菜单的结合体,用户先同过口令,3次自己关闭,用个IF就可以了,接着是接受功能键选择,根据SWITCH选择菜单里面我们需要的功能。0功能键是退出系统 2.5.1录入函数(creat)说明:这个函数把指针p1.p2指向新开的空间,然后再向空间里面写如数据,进而做成我们所需要的链表。 2.5.2浏览函数(out)说明:和录入函数差不多也是把P1指向新开的空间,不过不同的这次是从文件里面读入已经保存的数据。不是录入数据。 2.5.3查询函数(check)说明:先是用字符串比较函数STRCMP去找用户选择的查询方式,然后再用一个STRCMP一步一步在链表中再出信息,没有则退出。 2.5.4排序函数(score)说明:用字符串比较函数比较两个书名之间的大小,小在前,大在后。如果条件成立则交换结构体里面的数据。外面用选择循环就可以全部排序。 2.5.5删除函数(del)说明:利用指针的指向性,当STRCMP函数=0时找到要删除的图书信息时,把指向这个信息结构体的指针指向下一个结构体,把这个信息挡在链表外面。P2-》NEXT=P1》NEXT。 2.5.6修改函数(correct)说明:用STRCMP函数找到需要修改的书名,然后找到修改的类型,再输如修改后的信息。2.5.7文件保存函数(save)说明:用fwrite函数写入文件,当p->next!=0时一个一个吧数据写入文件知道p=NULL为止。 三.原代码程序3.1学生成绩排名#includevoidmain()/*这是主函数*/{inta[11],i,j,t;printf("请输入10个学生的成绩\n");for(i=0;i<10;i++)scanf("%d",&a[i]);printf("10个学生的成绩从高到低排列的顺序为\n");/*10个学生成绩排列代码*/for(i=0;i<10;i++){for(j=i+1;j<10;j++){if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n请再输入一个学生的成绩\n");scanf("%d",&a[10]);printf("11个学生的成绩从高到低排列的顺序为\n");/*11个学生成绩排列代码*/for(i=0;i<11;i++){for(j=i+1;j<11;j++){if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n11个学生成绩的反序排列为\n");/*11个学生成绩的反序排列代码*/for(i=0;i<=5;i++){t=a[i];a[i]=a[10-i];a[10-i]=t;}for(i=0;i<11;i++){printf("%d",a[i]);}printf("\n");}3.2根据条件进行学生成绩排名#includevoidmain()/*这是主的函数*/{int*sort1(inta[],intn);int*sort2(inta[],intn);int*sort3(inta[],intn);int*sort4(inta[],intn);intshow(intx[],inty,int(*(*fun)(inta[],intn)));intsort(inta[],intn,charstyle);intb[100],i,m;charc1;printf("要输入成绩的学生数n\n");scanf("%d",&m);printf("请输入%d个学生的成绩\n",m);for(i=0;i{scanf("%d",&b[i]);}printf("请选择排练方式\na:选择升序法\nd:选择降序法\nA:冒泡升序法\nD:冒泡降序法\n");scanf("%s",&c1);sort(b,m,c1);printf("%d个学生成绩排列后的顺序\n",m);for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
2.3链表的操作
2.5总流程图
说明:
这个基本是口令和菜单的结合体,用户先同过口令,3次自己关闭,用个IF就可以了,接着是接受功能键选择,根据SWITCH选择菜单里面我们需要的功能。
0功能键是退出系统
2.5.1录入函数(creat)
这个函数把指针p1.p2指向新开的空间,然后再向空间里面写如数据,进而做成我们所需要的链表。
2.5.2浏览函数(out)
和录入函数差不多也是把P1指向新开的空间,不过不同的这次是从文件里面读入已经保存的数据。
不是录入数据。
2.5.3查询函数(check)
先是用字符串比较函数STRCMP去找用户选择的查询方式,然后再用一个STRCMP一步一步在链表中再出信息,没有则退出。
2.5.4排序函数(score)
用字符串比较函数比较两个书名之间的大小,小在前,大在后。
如果条件成立则交换结构体里面的数据。
外面用选择循环就可以全部排序。
2.5.5删除函数(del)
利用指针的指向性,当STRCMP函数=0时找到要删除的图书信息时,把指向这个信息结构体的指针指向下一个结构体,把这个信息挡在链表外面。
P2-》NEXT=P1》NEXT。
2.5.6修改函数(correct)
用STRCMP函数找到需要修改的书名,然后找到修改的类型,再输如修改后的信息。
2.5.7文件保存函数(save)
用fwrite函数写入文件,当p->next!
=0时一个一个吧数据写入文件知道p=NULL为止。
三.原代码程序
3.1学生成绩排名
#include
voidmain()/*这是主函数*/
inta[11],i,j,t;
printf("请输入10个学生的成绩\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("10个学生的成绩从高到低排列的顺序为\n");/*10个学生成绩排列代码*/
for(j=i+1;j<10;j++)
if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n请再输入一个学生的成绩\n");scanf("%d",&a[10]);printf("11个学生的成绩从高到低排列的顺序为\n");/*11个学生成绩排列代码*/for(i=0;i<11;i++){for(j=i+1;j<11;j++){if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n11个学生成绩的反序排列为\n");/*11个学生成绩的反序排列代码*/for(i=0;i<=5;i++){t=a[i];a[i]=a[10-i];a[10-i]=t;}for(i=0;i<11;i++){printf("%d",a[i]);}printf("\n");}3.2根据条件进行学生成绩排名#includevoidmain()/*这是主的函数*/{int*sort1(inta[],intn);int*sort2(inta[],intn);int*sort3(inta[],intn);int*sort4(inta[],intn);intshow(intx[],inty,int(*(*fun)(inta[],intn)));intsort(inta[],intn,charstyle);intb[100],i,m;charc1;printf("要输入成绩的学生数n\n");scanf("%d",&m);printf("请输入%d个学生的成绩\n",m);for(i=0;i{scanf("%d",&b[i]);}printf("请选择排练方式\na:选择升序法\nd:选择降序法\nA:冒泡升序法\nD:冒泡降序法\n");scanf("%s",&c1);sort(b,m,c1);printf("%d个学生成绩排列后的顺序\n",m);for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
t=a[i];
a[i]=a[j];
a[j]=t;
}
printf("%d",a[i]);
printf("\n请再输入一个学生的成绩\n");
scanf("%d",&a[10]);
printf("11个学生的成绩从高到低排列的顺序为\n");/*11个学生成绩排列代码*/
for(i=0;i<11;i++)
for(j=i+1;j<11;j++)
if(a[i]{t=a[i];a[i]=a[j];a[j]=t;}}printf("%d",a[i]);}printf("\n11个学生成绩的反序排列为\n");/*11个学生成绩的反序排列代码*/for(i=0;i<=5;i++){t=a[i];a[i]=a[10-i];a[10-i]=t;}for(i=0;i<11;i++){printf("%d",a[i]);}printf("\n");}3.2根据条件进行学生成绩排名#includevoidmain()/*这是主的函数*/{int*sort1(inta[],intn);int*sort2(inta[],intn);int*sort3(inta[],intn);int*sort4(inta[],intn);intshow(intx[],inty,int(*(*fun)(inta[],intn)));intsort(inta[],intn,charstyle);intb[100],i,m;charc1;printf("要输入成绩的学生数n\n");scanf("%d",&m);printf("请输入%d个学生的成绩\n",m);for(i=0;i{scanf("%d",&b[i]);}printf("请选择排练方式\na:选择升序法\nd:选择降序法\nA:冒泡升序法\nD:冒泡降序法\n");scanf("%s",&c1);sort(b,m,c1);printf("%d个学生成绩排列后的顺序\n",m);for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
printf("\n11个学生成绩的反序排列为\n");/*11个学生成绩的反序排列代码*/
for(i=0;i<=5;i++)
a[i]=a[10-i];
a[10-i]=t;
printf("\n");
3.2根据条件进行学生成绩排名
voidmain()/*这是主的函数*/
int*sort1(inta[],intn);
int*sort2(inta[],intn);
int*sort3(inta[],intn);
int*sort4(inta[],intn);
intshow(intx[],inty,int(*(*fun)(inta[],intn)));
intsort(inta[],intn,charstyle);
intb[100],i,m;
charc1;
printf("要输入成绩的学生数n\n");
scanf("%d",&m);
printf("请输入%d个学生的成绩\n",m);
for(i=0;i{scanf("%d",&b[i]);}printf("请选择排练方式\na:选择升序法\nd:选择降序法\nA:冒泡升序法\nD:冒泡降序法\n");scanf("%s",&c1);sort(b,m,c1);printf("%d个学生成绩排列后的顺序\n",m);for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
scanf("%d",&b[i]);
printf("请选择排练方式\na:
选择升序法\nd:
选择降序法\nA:
冒泡升序法\nD:
冒泡降序法\n");
scanf("%s",&c1);
sort(b,m,c1);
printf("%d个学生成绩排列后的顺序\n",m);
for(i=0;iprintf("%d",b[i]);printf("\n");}intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/{if(style=='a')show(a,n,sort1);elseif(style=='d')show(a,n,sort2);elseif(style=='A')show(a,n,sort3);elseif(style=='D')show(a,n,sort4);return(*a);}int*sort1(inta[],intn)/*这是选择法升序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
printf("%d",b[i]);
intsort(inta[],intn,charstyle)/*这是根据调用SHOW函数的函数*/
if(style=='a')
show(a,n,sort1);
elseif(style=='d')
show(a,n,sort2);
elseif(style=='A')
show(a,n,sort3);
elseif(style=='D')
show(a,n,sort4);
return(*a);
int*sort1(inta[],intn)/*这是选择法升序的函数*/
inti,j,t;
for(i=0;i{for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
for(j=i+1;j{if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
if(a[j]{t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort2(inta[],intn)/*这是选择法降序的函数*/{inti,j,t;for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
return(a);
int*sort2(inta[],intn)/*这是选择法降序的函数*/
for(i=0;i{for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
for(j=i+1;j{if(a[j]>a[i]){t=a[i];a[i]=a[j];a[j]=t;}}}return(a);}int*sort3(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
if(a[j]>a[i])
int*sort3(inta[],intn)/*这是冒泡法升序的函数*/
for(j=0;j{for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
for(i=0;i{if(a[i]>a[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}int*sort4(inta[],intn)/*这是冒泡法升序的函数*/{inti,j,t;for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
if(a[i]>a[i+1])
a[i]=a[i+1];
a[i+1]=t;
int*sort4(inta[],intn)/*这是冒泡法升序的函数*/
for(j=0;j{for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
for(i=0;i{if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
if(a[i]{t=a[i];a[i]=a[i+1];a[i+1]=t;}}}return(a);}intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/{int*z;z=(*fun)(x,y);return(*z);}3.3链表的操作#include#include#defineLENsizeof(structstudent)structstudent{longnum;floatscore;structstudent*next;};intn;structstudent*creat(void)/*这是建立链表函数*/{structstudent*head;structstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%ld,%f",&p1->num,&p1->score);}p2->next=NULL;return(head);}voidprint(structstudent*head)/*这是输出链表函数*/{structstudent*p;printf("\n这%d个学生的成绩记录为:\n",n);p=head;if(head!=NULL)do{printf("%ld%5.1f\n",p->num,p->score);p=p->next;}while(p!=NULL);}voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最高分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最高分的是:\n");p2=p1->next;do{if(p2->score>p1->score)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/{structstudent*p1,*p2;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生最低分的是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生最低分的是:\n");p2=p1->next;do{if(p2->scorescore)p1=p2;p2=p2->next;}while(p2!=NULL);printf("%5.1f\n",p1->score);}}voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/{structstudent*p1;floatsum=0,avr=0,n=0;p1=head;if(head==NULL){printf("列表为空\n");}elseif(p1->next==NULL){printf("现在,这些学生的平均分是:\n");printf("%5.1f\n",p1->score);}else{printf("现在,这些学生的平均分是:\n");while(p1!=NULL){sum=sum+p1->score;p1=p1->next;n=n+1;}avr=sum/n;printf("%5.1f\n",avr);}}voidscores(structstudent*head)/*这是学生分数的排序函数*/{structstudent*p1,*p2;
intshow(intx[],inty,int(*(*fun)(inta[],intn)))/*这是SHOW通用输出函数*/
int*z;
z=(*fun)(x,y);
return(*z);
3.3链表的操作
#defineLENsizeof(structstudent)
structstudent
floatscore;
structstudent*next;
intn;
structstudent*creat(void)/*这是建立链表函数*/
structstudent*head;
structstudent*p1,*p2;
n=0;
p1=p2=(structstudent*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!
=0)
n=n+1;
if(n==1)head=p1;
elsep2->next=p1;
p2=p1;
p1=(structstudent*)malloc(LEN);
p2->next=NULL;
return(head);
voidprint(structstudent*head)/*这是输出链表函数*/
structstudent*p;
printf("\n这%d个学生的成绩记录为:
\n",n);
p=head;
if(head!
=NULL)
do
printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}while(p!
=NULL);
voidnumbermax(structstudent*head)/*这是找出学生最高分的函数*/
p1=head;
if(head==NULL)
printf("列表为空\n");
elseif(p1->next==NULL)
{printf("现在,这些学生最高分的是:
\n");
printf("%5.1f\n",p1->score);
else
p2=p1->next;
if(p2->score>p1->score)
p1=p2;
p2=p2->next;
}while(p2!
voidnumbermin(structstudent*head)/*这是找出学生最低分的函数*/
{printf("现在,这些学生最低分的是:
if(p2->scorescore)
voidnumberavr(structstudent*head)/*这是找出学平均分的函数*/
structstudent*p1;
floatsum=0,avr=0,n=0;
{printf("现在,这些学生的平均分是:
while(p1!
sum=sum+p1->score;
p1=p1->next;
avr=sum/n;
printf("%5.1f\n",avr);
voidscores(structstudent*head)/*这是学生分数的排序函数*/
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1