资源描述:
《数据结构之排序总结(c语言)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、〃数据结构实验课程Z手工执行一下排序算法,〃写出每一趟排序结束时的关键码状态#include#include#definemaxsize20〃结构体的定义typedefstruct{intL[maxsize+1];intlength;}list;〃以F是八种排序方法的子函数的说明voiddisplay(listm);〃输出函数voidmenu(listm);〃菜单函数voidstraight(listm);〃直接插入排序voidshell(listm);〃希尔排序(增量
2、d[lJ=5)voidbubble(listm);〃起泡排序voidquick(listm);〃快速排序voidsclcction(listm);//简单选择排序voidheap(listm);〃堆排序voidmerg(listm);〃归并排序voidradix(listm);〃基数排序voidshellinsert(list*m,intnum);voidqsort(list*m,intlow,inthigh);intpartition(listlow,inthigh);intselectmin(list*
3、m,intnum);voidheapadjust(lists,intn);voidmsort(intsr[],inttrl[],ints,intt);voidmer(intsr[],inttr[],inti,intm,intt);〃主函数voidmain(){lista;inti;charch;printf(HFirstly,let*screatethelist.n);printf(npleaseinputthelengthofthelist:M);scanf(r'%d",&a.length);pr
4、intf(nplcascinputthekeywordofthelist:H);for(i=1;i<=a.length;i++)scanf(H%d&a.L[i]);display(a);getchar();printf(MLet,sgotothemenun);getchar();systcm(HclsH);do{menu(a);printf(nDoyouwanttocontinue?(Y/N)H);fflush(stdin);scanf("%c",&ch);getchar();syst
5、em(nclsn);}while(ch==yilch==,Y,);voiddisplay(listm){inti;printf(”ThelistisfollowingAn");for(i=1;i<=m」ength;i++){printf(”・・%d・・”,m.L[i]);〃菜单界面voidmenu(listm){intnumber;printf(Ml*A*A*A*A*A*A*A*A*A*A*A*A*MENU*人*人*八*八*八*八*/*人*八*八*八*八*
6、口”)・printf(ulAoAoAoAo
7、A1.StraightInsertionSortAoAoAoAoAll门;printf(HlAoAoAoAoA2.Shell'sSortAoAoAoAoAl『);printf(H
8、AoAoAqAoA3.BubbleSortaoaoaoaoa
9、“);printf(HlAoAoAoAoA4.QuickSortAoAoAqAoA
10、“);printf("
11、AOAOAOAOA5.SimpleSelectionSortAoAoAoAoAl“);printf(H
12、AoAoAoAoA6.HeapSortAo
13、AoAoAoAlM);printf(HlAoAoAoAoA7.MergingSortAOAOAOAOAIn);printf("lAoAoAoAoA8.RadixSortAOAOAOAOAI“);printf(MPleaseinputyourchoice:M);scanf(M%d,&number);switch(number){case1:straight(m);break;case2:shell(m);break;case3:bubble(m);break;case4:quick(m);b
14、reak;case5:sclcction(m);brcak;case6:heap(m);break;case7:merg(m);break;case8:radix(m);break;default:printf(nYourchoiceiswrong!u);voidstraight(listm){inti,j,num=l;display(m);for(i=2;i<=mJength;i++){{m.L[0]=m.