数据结构实验---排序.doc
上传人:sy****28 上传时间:2024-09-14 格式:DOC 页数:3 大小:20KB 金币:16 举报 版权申诉
预览加载中,请您耐心等待几秒...

数据结构实验---排序.doc

数据结构实验---排序.doc

预览

在线预览结束,喜欢就下载吧,查找使用更方便

16 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include"stdio.h"#include"string.h"typedefstructStudentInfo{charID[11];char*name;floatscore;}StudentInfo;StudentInfoStuInfo[12]={{"0800301105","JACK",95},{"0800201505","LUN",85},{"0400820115","MARY",75.5},{"0400850122","KATE",78.9},{"0500201011","LILI",88},{"0800401105","JACK",96},{"0600830105","JAN",98.4},{"0952520012","SAM",75},{"9721000045","OSCAR",64},{"0700301105","JACK",97},{"0458003312","ZOE",68.9},{"0400830211","BOBI",87.6}};intgtid(StudentInfo*a,StudentInfo*b){returnstrcmp(a->ID,b->ID)>0;}intitid(StudentInfo*a,StudentInfo*b){returnstrcmp(a->ID,b->ID)<0;}intgtname(StudentInfo*a,StudentInfo*b){returnstrcmp(a->name,b->name)>0;}intitname(StudentInfo*a,StudentInfo*b){returnstrcmp(a->name,b->name)<0;}intgtscore(StudentInfo*a,StudentInfo*b){return(a->score)>(b->score);}intitscore(StudentInfo*a,StudentInfo*b){return(a->score)<(b->score);}voidInsertionSort(StudentInfoA[],intN,intg(StudentInfo*,StudentInfo*)){intj,P;StudentInfoTmp;for(P=1;P<N;P++){Tmp=A[P];for(j=P;j>0&&g(&A[j-1],&Tmp);j--)A[j]=A[j-1];A[j]=Tmp;}}voidShellsort(StudentInfoA[],intN,intgt(StudentInfo*,StudentInfo*)){inti,j,Increment;StudentInfoTmp;for(Increment=N/2;Increment>0;Increment/=2)for(i=Increment;i<N;i++){Tmp=A[i];for(j=i;j>=Increment;j-=Increment)if(gt(&A[j-Increment],&Tmp))A[j]=A[j-Increment];elsebreak;A[j]=Tmp;}}voidinitStudentInfo(StudentInfoa[]){inti;for(i=0;i<12;i++)a[i]=StuInfo[i];}voidptinStudentInfo(StudentInfoa[]){inti;for(i=0;i<12;i++)printf("%s%6s%.2f\n",a[i].ID,a[i].name,a[i].score);}main(){StudentInfonow[12];printf("原始数据:\n");initStudentInfo(now);ptinStudentInfo(now);printf("插入排序,学号递增:\n");initStudentInfo(now);InsertionSort(now,12,gtid);ptinStudentInfo(now);printf("插入排序,名字递增:\n");initStudentInfo(now);InsertionSort(now,12,gtname);ptinStudentInfo(now);printf("快速排序,名字递增:\n");initStudentInfo(now);Shellsort(now,12,gtname);ptinStudentInfo(now);printf("快速排序,