




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验课题:【用C描述课本的同学】有以下结构体构成的数组:struct StudentInfo char ID10;char * name;float score;StuInfo12="0800301105", "JACK", 95,"0800201505", "LUN", 85,"0400820115", "MARY", 75.5,"0400850122", "KATE", 78.9,"0500201011", &q
2、uot;LILI", 88,"0800401105", "JACK", 96,"0600830105", "JAN", 98.4,"0952520012", "SAM", 75,"9721000045", "OSCAR", 64,"0700301105", "JACK", 97,"0458003312", "ZOE", 68.9,"040
3、0830211", "BOBI", 87.6 ; 1 使用直接插入的排序方法按照学号的顺序对以上数组进行排序(递增);2 分别用归并排序和快速排序按照姓名的顺序对以上数组进行排序(递增),有3人的名字是"JACK",注意观察排序是否稳定。程序代码:第一种:#include #include #include #include #define Cutoff (3struct StudentInfo char ID10;char * name;double score;StuInfo12="0800301105", "
4、JACK", 95,"0800201505", "LUN", 85,"0400820115", "MARY", 75.5,"0400850122", "KATE", 78.9,"0500201011", "LILI", 88,"0800401105", "JACK", 96,"0600830105", "JAN", 98.4,"09525
5、20012", "SAM", 75,"0721000045", "OSCAR", 64,"0700301105", "JACK", 97,"0458003312", "ZOE", 68.9,"0400830211", "BOBI", 87.6 ,; void InsertionSort(struct StudentInfo A,int Nint j,p;struct StudentInfo Tmp;for(
6、p=1;p Tmp = Ap;for(j=p; j>0&&strcmp(Aj-1.ID,Tmp.ID>0 ; j-Aj=Aj-1;Aj=Tmp;void InsertionSort1(struct StudentInfo A,int Nint j,p;struct StudentInfo Tmp;for(p=1;p Tmp = Ap;for(j=p; j>0&&strcmp(A,T>0 ; j-Aj=Aj-1;Aj=Tmp;void Merge(struct StudentInfo A,struct Stud
7、entInfo TmpArray,int Lpos,int Rpos,int RightEndint i,LeftEnd,NumElements,TmpPos;LeftEnd=Rpos-1;TmpPos=Lpos;NumElements=RightEnd-Lpos+1;while(Lpos<=LeftEnd && Rpos<=RightEndif(strcmp(AL,AR<=0TmpArrayTmpPos+=ALpos+;elseTmpArrayTmpPos+=ARpos+;while(Lpos<=LeftEndTmpAr
8、rayTmpPos+=ALpos+;while(Rpos<=RightEndTmpArrayTmpPos+=ARpos+;for(i=0;i ARightEnd=TmpArrayRightEnd;void MSort(struct StudentInfo A,struct StudentInfo TmpArray,int Left,int Rightint Center;if(Left Center=(Left+Right/2;MSort(A,TmpArray,Left,Center;MSort(A,TmpArray,Center+1,Right;Merge(A,TmpArray,Lef
9、t,Center+1,Right;void Mergesort(struct StudentInfo A,int Nstruct StudentInfo *TmpArray;TmpArray=malloc(N*sizeof(struct StudentInfo;if(TmpArray !=NULLMSort(A,TmpArray,0,N-1;free(TmpArray;elseprintf("No space for tmp array!"void Swap(struct StudentInfo A,struct StudentInfo Bstruct StudentInf
10、o *Tmp;Tmp=A;A=B;B=Tmp;struct StudentInfo Median3(struct StudentInfo A,int Left,int Rightstruct StudentInfo Tmp;int Center=(Left+Right/2;if(strcmp(AL,AC>0Swap(&ALeft,&ACenter;if(strcmp(AL,AR>0Swap(&ALeft,&ARight;if(strcmp(AC,ARight.n
11、ame>0Swap(&ACenter,&ARight;Swap(&ACenter,&ARight-1;return ARight-1;void Qsort(struct StudentInfo A,int Left,int Rightint i,j;struct StudentInfo Pivot,Tmp;if(Left+Cutoff<=RightPivot=Median3(A,Left,Right;i=Left;j=Right-1;for(;while(strcmp(A+,P<0while(strcmp(A-j.
12、name,P>0if(i Swap(&Ai,&Aj;Tmp=Ai;Ai=Aj; Aj=Tmp;elsebreak; Cu + FeQsort(A,Left,i-1;Qsort(A,i+1,Right;(3) InsertionSort1(A+Left,Right-Left+1;void Quicksort(struct StudentInfo A,int NQsort(A,0,N-1;=CO2-void main(int i=0;InsertionSort(StuInfo,12;for(i=0;i<12;i+(4)适量Ba(NO3)2 溶液 Ba2
13、+SO=BaSO4三、推断题(10分)24、(1)(4分 Mergesort(StuInfo,12;for(i=0;i<12;i+printf("%s,%s,%0.1fn",StuInfoi.ID,StuI,StuInfoi.score;Na 2 O 2 for(i=0;i<12;i+ printf("%s,%s,%0.1fn",StuInfoi.ID,StuI,StuInfoi.score;- "0800301105","JACK",95, )(6分)"0
14、500201011","LILI",88,"0800401105","JACK",96,"0600830105","JAN",98.4,"0952520012","SAM",75,"9721000045","OSCAR",64,"0700301105","JACK",97,"0458003312","ZOE",68.9,&quo
15、t;0400830211","BOBI",87.6;void InsertionSort(ElementType A,int Nint j,P;ElementType Tmp;for(P=1;P Tmp=AP;for(j=P;j>0&&strcmp(Aj-1.ID,Tmp.ID>0;j-Aj=Aj-1;Aj=Tmp;void InsertionSort2(ElementType A,int Nint j,P;ElementType Tmp;for(P=1;P Tmp=AP;for(j=P;j>0&&strcmp(A
16、,T>0;j-Aj=Aj-1;Aj=Tmp;void Merge (ElementType A,ElementType TmpArray,int Lpos,int Rpos,int RightEndint i,LeftEnd,NumElements,Tmpos;LeftEnd=Rpos-1;Tmpos=Lpos;NumElements=RightEnd-Lpos+1;while(Lpos<=LeftEnd&&Rpos<=RightEndif(strcmp(AL,AR<=0TmpArrayTmp
17、os+=ALpos+;elseTmpArrayTmpos+=ARpos+;while(Lpos<=LeftEndTmpArrayTmpos+=ALpos+;while(Rpos<=RightEndTmpArrayTmpos+=ARpos+;for(i=0;i ARightEnd=TmpArrayRightEnd;void MSort(ElementType A,ElementType TmpArray,int Left,int Rightint center;if(Left center=(Left+Right/2;MSort(A,TmpArray,Left,center;MSor
18、t(A,TmpArray,center+1,Right;Merge(A,TmpArray,Left,center+1,Right;void Mergsort(ElementType A,int NElementType *TmpArray;TmpArray=(ElementType*malloc(N*sizeof(ElementType;if(TmpArray!=NULLMSort(A,TmpArray,0,N-1;free(TmpArray;elseprintf("No space for tmp array!"void Swap(ElementType *A,Eleme
19、ntType *BElementType XX;XX=*A;*A=*B;*B=XX;ElementType Median3(ElementType A,int Left,int Rightint Center=(Left+Right/2;if(strcmp(AL,AC>0Swap(&ALeft,&ACenter;if(strcmp(AL,AR>0Swap(&ALeft,&ARight;if(strcmp(AC,AR>0Swap(&ACenter,&ARight;Swap(&ACenter,&ARight-1;return ARight-1;#define Cutoff 3void Qsort(ElementType A,int Left,int Rightint i,j;ElementType Pivot;if(Left+Cutoff<=RightPivot=Median3(A,Left,R
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江苏省常州市溧阳市2024-2025学年六年级下学期期中数学试题(含答案)
- 2025年湖北省初中毕业生学业水平考试历史综合试卷(四)(教师版)
- 河北中医药大学《供水水文地质》2023-2024学年第二学期期末试卷
- 四川省南充市2024-2025学年三下数学期末监测试题含解析
- 天府新区航空旅游职业学院《人文生物学》2023-2024学年第二学期期末试卷
- 淮安市2025年六年级数学小升初摸底考试含解析
- 四川大学《卫生法学B》2023-2024学年第一学期期末试卷
- 厦门软件职业技术学院《家居纹样设计》2023-2024学年第一学期期末试卷
- 浙江省温州市十五校联合体2025届招生全国统一考试广东英语试题调研卷含解析
- 华北理工大学冀唐学院《大众健身流行课程》2023-2024学年第一学期期末试卷
- 2024年司法考试历年真题答案
- 八颗行星课件-科学六年级下册教科版
- 2025年上半年福建福州平潭综合实验区文旅发展集团限公司招聘11人易考易错模拟试题(共500题)试卷后附参考答案
- 2025湖南长沙振望投资发展有限公司招聘8人笔试参考题库附带答案详解
- 承插型盘扣式钢管脚手架安全技术标准JGJT231-2021规范解读
- 企业安全风险分级管控和隐患排查治理工作指南
- 2025年4月自考15040习概押题及答案
- 湖北省十一校2025届高三第二次联考数学试卷(含答案)
- 2025届高考物理一轮复习:人教版(2019)高中物理必修第二册基础知识自测填空练习题(含答案)
- 2025年安阳职业技术学院单招职业技能测试题库附答案
- 中小学生心理健康教育的研究与实践进展
评论
0/150
提交评论