数据结构课件设计多种排序.docx
《数据结构课件设计多种排序.docx》由会员分享,可在线阅读,更多相关《数据结构课件设计多种排序.docx(26页珍藏版)》请在冰豆网上搜索。
数据结构课件设计多种排序
课程设计说明书
课程名称:
数据结构课程设计
设计题目:
多种排序
院系:
计算机科学与信息工程学院
学生姓名:
徐思勇
学号:
200903010016
专业班级:
09级计科班(应用)
指导教师:
孙高飞
2011年6月8日
课程设计任务书
设计题目
学生姓名
所在院系
计科院
专业、年级、班
09级计科应用班
设计要求:
利用随机函数产生N个随机整数(10000以上),对这些数进行多种方法进行排序
学生应完成的工作:
1)采用如下六种方法实现上述问题求解:
插入排序、希尔排序、起泡排序、快速排序、选择排序、堆排序。
2)统计每一种排序方法的性能(以上机运行程序所花费的时间为准进行对比),找出其中两种较快的方法。
并将数据序列和不同的查找算法的性能结果记录入txt文件。
参考文献阅读:
1)清华大学出版社《数据结构》编著:
严蔚敏吴伟民
2)清华大学出版社《C程序设计教程》编著:
谭浩强
工作计划:
1)两天时间讨论框架,由组长分配任务。
2)三人合作每人解决两种排序方法由组长组合起来。
任务下达日期:
2011年6月7日
任务完成日期:
2001年6月13日
指导教师(签名):
学生(签名):
李志祥
摘要:
本次课程设计所要求的排序方法有插入排序、希尔排序、起泡排序、快速排序、选择排序、堆排序,基本上将我们学习过的排序方法都囊括在内,可以说这次课程设计是对我们学过的排序算法的一个总结和对比。
通过实验中各种排序方法所用的时间对比,可以让我们对每种排序方法的性能有一个清晰的认识,有利于我们以后在做某些程序时更好的选择最好的排序方法。
关键词:
(1)六种排序①插入排序②希尔排序③起泡排序④快速排序
⑤选择排序⑥堆排序
(2)排序方法的性能
关键问题:
核心问题:
排列组合
数据模型(逻辑结构):
30000个随机数
存储结构:
保存在不同的文件
核心算法:
直接插入、直接选择、冒泡、快速排序、堆排序的算法
输入数据:
初始化数组:
rand()%50000+1
输出数据:
排序内容到文件,排序所用时间
目录
1.设计背景………………………………………………………5
1.1总设计………………………………………………………5
2.设计方案………………………………………………………5
2.1设计思想……………………………………………………5
2.2主要思想和流程图…………………………………………6
3方案实施………………………………………………………7
3.1程序的实现…………………………………………………7
3.2主要源代码及说明…………………………………………7
4结果与结论……………………………………………………20
4.1运行主界面…………………………………………………20
4.2各种排序方法运行结果……………………………………20
4.3运行结论……………………………………………………24
5收获与致谢……………………………………………………24
6参考文献………………………………………………………24
7附件………………………………………………………24
1.设计背景
1.1总设计
分别实现直接插入排序、希尔排序、直接选择排序、冒泡排序、快速排序、堆排序的算法。
从时间的角度来分析各种排序的性能。
通过测试多组数据来掌握各种排序的方法及适用场合,并能在解决实际问题灵活运用。
在编写代码的时候,有以下几个问题:
(1)建立一个主函数,在主函数中要有菜单界面,和输入功能键相应执行的功能。
并且要求能循环使用系统。
(2)分别实现直接插入排序、希尔排序、直接选择排序、冒泡排序、快速排序、堆排序的算法。
(3)通过冒泡排序法来测试每组数据用那种排序算法最优。
2.设计方案
2.1设计思想
建立一个主函数,在主函数中要有菜单界面,和输入功能键相应执行的功能。
分别实现直接插入、直接选择、冒泡、快速排序、堆排序的算法。
(1)直接插入排序的基本思想是基于插入,开始假定第一个记录有序,然后从第二个记录开始,依次插入到前面有序的子文件中。
即将记录a[i](2<=i<=n)插入到有序子序列a[1..i-1]中,使记录的有序序列从a[1..i-1]变为a[1..i],最终使整个文件有序。
共进行n-1趟插入。
最坏时间复杂度是0(n2),平均时间复杂度是0(n2),空间复杂度是O
(1),是稳定排序。
(2)希尔排序的基本思想是基于分组,先取一个小于n的整数d1作为第一个增量,把文件的全部记录分成d1个组。
所有距离为d1的倍数的记录放在同一个组中。
先在各组内进行直接插入排序;然后,取第二个增量d2(3)直接选择排序的基本思想是基于选择,开始有序序列长度为零,第i(1<=i共进行n-1趟选择。最坏时间复杂度是0(n2),平均时间复杂度是0(n2),空间复杂度是O(1),是不稳定排序。(4)冒泡排序:首先将第一个记录的关键字和第二个记录的关键字进行比较,若为逆序,则将两个记录交换,然后比较第二个记录和第三个记录的关键字。依此类推,直到第N-1和第N个记录的关键字进行过比较为止。上述为第一趟排序,其结果使得关键字的最大纪录被安排到最后一个记录的位置上。然后进行第二趟起泡排序,对前N-1个记录进行同样操作。一共要进行N-1趟起泡排序。(5)快速排序思想:从待排序列中任取一个元素(例如取第一个)作为中心,所有比它小的元素一律前放,所有比它大的元素一律后放,形成左右两个子表;然后再对各子表重新选择中心元素并依此规则调整,直到每个子表的元素只剩一个。此时便为有序序列了。(6)堆排序基本思想是:堆是n个元素的序列,先建堆,即先选得一个关键字最大或最小的记录,然后与序列中最后一个记录交换,之后将序列中前n-1记录重新调整为堆(调堆的过程称为“筛选”),再将堆顶记录和当前堆序列的最后一个记录交换,如此反复直至排序结束。优点是在时间性能与树形选择排序属同一量级的同时,堆排序只需要一个记录大小供交换用的辅助空间,调堆时子女只和双亲比较。避免了过多的辅助存储空间及和最大值的比较。2.2主要算法和流程图输入序号退出显示随机数时间效率比较堆排序快速排序冒泡排序直接选择排序希尔排序直接插入排序结束显示各个排序法对同一组数据排序所用的时间和其中较快的两种方法显示排序后的数据和时间效率开始1234567803.方案实施3.1程序的实现程序实现时应考虑的问题3.2主要源代码及说明#include#include#include#include#include#defineN10000voidWrong(){printf("\n=====>按键错误!\n");getchar();}voidDisp(inta[]){inti;system("cls");for(i=0;i{if((i-1)%10==9)printf("\n");printf("%-7d",a[i]);}}voidInsertSort(inta[],intp)//插入排序{inti,j,temp;for(i=1;i{temp=a[i];for(j=i;j>0&&a[j-1]>temp;j--)a[j]=a[j-1];a[j]=temp;}}voidshellSort(inta[],intp)//希尔排序{inti,j,temp;for(i=p;i{if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
(3)直接选择排序的基本思想是基于选择,开始有序序列长度为零,第i(1<=i共进行n-1趟选择。最坏时间复杂度是0(n2),平均时间复杂度是0(n2),空间复杂度是O(1),是不稳定排序。(4)冒泡排序:首先将第一个记录的关键字和第二个记录的关键字进行比较,若为逆序,则将两个记录交换,然后比较第二个记录和第三个记录的关键字。依此类推,直到第N-1和第N个记录的关键字进行过比较为止。上述为第一趟排序,其结果使得关键字的最大纪录被安排到最后一个记录的位置上。然后进行第二趟起泡排序,对前N-1个记录进行同样操作。一共要进行N-1趟起泡排序。(5)快速排序思想:从待排序列中任取一个元素(例如取第一个)作为中心,所有比它小的元素一律前放,所有比它大的元素一律后放,形成左右两个子表;然后再对各子表重新选择中心元素并依此规则调整,直到每个子表的元素只剩一个。此时便为有序序列了。(6)堆排序基本思想是:堆是n个元素的序列,先建堆,即先选得一个关键字最大或最小的记录,然后与序列中最后一个记录交换,之后将序列中前n-1记录重新调整为堆(调堆的过程称为“筛选”),再将堆顶记录和当前堆序列的最后一个记录交换,如此反复直至排序结束。优点是在时间性能与树形选择排序属同一量级的同时,堆排序只需要一个记录大小供交换用的辅助空间,调堆时子女只和双亲比较。避免了过多的辅助存储空间及和最大值的比较。2.2主要算法和流程图输入序号退出显示随机数时间效率比较堆排序快速排序冒泡排序直接选择排序希尔排序直接插入排序结束显示各个排序法对同一组数据排序所用的时间和其中较快的两种方法显示排序后的数据和时间效率开始1234567803.方案实施3.1程序的实现程序实现时应考虑的问题3.2主要源代码及说明#include#include#include#include#include#defineN10000voidWrong(){printf("\n=====>按键错误!\n");getchar();}voidDisp(inta[]){inti;system("cls");for(i=0;i{if((i-1)%10==9)printf("\n");printf("%-7d",a[i]);}}voidInsertSort(inta[],intp)//插入排序{inti,j,temp;for(i=1;i{temp=a[i];for(j=i;j>0&&a[j-1]>temp;j--)a[j]=a[j-1];a[j]=temp;}}voidshellSort(inta[],intp)//希尔排序{inti,j,temp;for(i=p;i{if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
共进行n-1趟选择。
(1),是不稳定排序。
(4)冒泡排序:
首先将第一个记录的关键字和第二个记录的关键字进行比较,若为逆序,则将两个记录交换,然后比较第二个记录和第三个记录的关键字。
依此类推,直到第N-1和第N个记录的关键字进行过比较为止。
上述为第一趟排序,其结果使得关键字的最大纪录被安排到最后一个记录的位置上。
然后进行第二趟起泡排序,对前N-1个记录进行同样操作。
一共要进行N-1趟起泡排序。
(5)快速排序思想:
从待排序列中任取一个元素(例如取第一个)作为中心,所有比它小的元素一律前放,所有比它大的元素一律后放,形成左右两个子表;然后再对各子表重新选择中心元素并依此规则调整,直到每个子表的元素只剩一个。
此时便为有序序列了。
(6)堆排序基本思想是:
堆是n个元素的序列,先建堆,即先选得一个关键字最大或最小的记录,然后与序列中最后一个记录交换,之后将序列中前n-1记录重新调整为堆(调堆的过程称为“筛选”),再将堆顶记录和当前堆序列的最后一个记录交换,如此反复直至排序结束。
优点是在时间性能与树形选择排序属同一量级的同时,堆排序只需要一个记录大小供交换用的辅助空间,调堆时子女只和双亲比较。
避免了过多的辅助存储空间及和最大值的比较。
2.2主要算法和流程图
输入序号
退出
显示随机数
时间效率比较
堆排序
快速排序
冒泡排序
直接选择排序
希尔排序
直接插入排序
结束
显示各个排序法对同一组数据排序所用的时间和其中较快的两种方法
显示排序后的数据和时间效率
开始
12345678
0
3.方案实施
3.1程序的实现
程序实现时应考虑的问题
3.2主要源代码及说明
#include
#defineN10000
voidWrong()
{
printf("\n=====>按键错误!
\n");
getchar();
}
voidDisp(inta[])
inti;
system("cls");
for(i=0;i{if((i-1)%10==9)printf("\n");printf("%-7d",a[i]);}}voidInsertSort(inta[],intp)//插入排序{inti,j,temp;for(i=1;i{temp=a[i];for(j=i;j>0&&a[j-1]>temp;j--)a[j]=a[j-1];a[j]=temp;}}voidshellSort(inta[],intp)//希尔排序{inti,j,temp;for(i=p;i{if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
if((i-1)%10==9)
printf("\n");
printf("%-7d",a[i]);
voidInsertSort(inta[],intp)//插入排序
inti,j,temp;
for(i=1;i{temp=a[i];for(j=i;j>0&&a[j-1]>temp;j--)a[j]=a[j-1];a[j]=temp;}}voidshellSort(inta[],intp)//希尔排序{inti,j,temp;for(i=p;i{if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
temp=a[i];
for(j=i;j>0&&a[j-1]>temp;j--)
a[j]=a[j-1];
a[j]=temp;
voidshellSort(inta[],intp)//希尔排序
for(i=p;i{if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
if(a[i]{temp=a[i];for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
for(j=i-p;j>=0&&(tempa[j+p]=a[j];a[j+p]=temp;}}}voidSelectSort(inta[],intp)//选择排序{inti,j,k;for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
a[j+p]=a[j];
a[j+p]=temp;
voidSelectSort(inta[],intp)//选择排序
inti,j,k;
for(i=0;i{k=i;for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
k=i;
for(j=i+1;jif(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
if(a[j]k=j;if(k!=i){inttemp;temp=a[k];a[k]=a[i];a[i]=temp;}}}voidBubbleSort(inta[],intp)/*冒泡排序算法*/{inti,j,temp;for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
k=j;
if(k!
=i)
inttemp;
temp=a[k];
a[k]=a[i];
a[i]=temp;
voidBubbleSort(inta[],intp)/*冒泡排序算法*/
for(i=0;i{for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
for(j=N-1;j>i;j--)/*比较,找出本趟最小关键字的记录*/
if(a[j]{temp=a[j];/*进行交换,将最小关键字记录前移*/a[j]=a[j-1];a[j-1]=temp;}}}voidcreatheap(inta[],inti,intn)//创建堆{intj;intt;t=a[i];j=2*(i+1)-1;while(j<=n){if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
temp=a[j];/*进行交换,将最小关键字记录前移*/
a[j-1]=temp;
voidcreatheap(inta[],inti,intn)//创建堆
intj;
intt;
t=a[i];
j=2*(i+1)-1;
while(j<=n)
if((jj++;if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
j++;
if(t{a[i]=a[j];i=j;j=2*(i+1)-1;}elsej=n+1;}a[i]=t;}voidheapsort(inta[],intn,intp)//堆排序{inti;intt;for(i=n/2-1;i>=0;i--)creatheap(a,i,n-1);for(i=n-1;i>=1;i--){t=a[0];a[0]=a[i];a[i]=t;creatheap(a,0,i-1);}}voidquicksort(inta[],intn,intp){inti,j,low,high,temp,top=-1;structnode{intlow,high;}st[N];top++;st[top].low=0;st[top].high=n-1;while(top>-1){low=st[top].low;high=st[top].high;top--;i=low;j=high;if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
a[i]=a[j];
i=j;
else
j=n+1;
a[i]=t;
voidheapsort(inta[],intn,intp)//堆排序
for(i=n/2-1;i>=0;i--)
creatheap(a,i,n-1);
for(i=n-1;i>=1;i--)
t=a[0];
a[0]=a[i];
creatheap(a,0,i-1);}
voidquicksort(inta[],intn,intp)
inti,j,low,high,temp,top=-1;
structnode
intlow,high;
}st[N];
top++;
st[top].low=0;st[top].high=n-1;
while(top>-1)
{low=st[top].low;high=st[top].high;
top--;
i=low;j=high;
if(low{temp=a[low];while(i!=j){while(itemp)j--;if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
{temp=a[low];
while(i!
=j)
{while(itemp)j--;
if(iwhile(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
while(iif(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
if(i}a[i]=temp;top++;st[top].low=low;st[top].high=i-1;top++;st[top].low=i+1;st[top].high=high;}}}doubleTInsertSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
top++;st[top].low=low;st[top].high=i-1;
top++;st[top].low=i+1;st[top].high=high;
doubleTInsertSort(inta[],intp)
intb[N];
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用直接插入排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接插入排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
b[i]=a[i];
LARGE_INTEGERm_liPerfFreq={0};
QueryPerformanceFrequency(&m_liPerfFreq);
LARGE_INTEGERm_liPerfStart={0};
QueryPerformanceCounter(&m_liPerfStart);
InsertSort(b,p);
LARGE_INTEGERliPerfNow={0};
QueryPerformanceCounter(&liPerfNow);
doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;
time/=m_liPerfFreq.QuadPart;
if(p!
=7)
{Disp(b);getchar();}
printf("\n用直接插入排序法用的时间为%f秒;",time);
FILE*fp;
fp=fopen("直接插入排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTShellSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
fprintf(fp,"%d",b[i]);
fclose(fp);
return(time);
doubleTShellSort(inta[],intp)
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);InsertSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n希尔排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("希尔排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
printf("\n希尔排序法用的时间为%f秒;",time);
fp=fopen("希尔排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTSelectSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
doubleTSelectSort(inta[],intp)
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);SelectSort(b,p);if(p!=7){Disp(b);getchar();}LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;printf("\n用直接选择排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("直接选择排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
SelectSort(b,p);
printf("\n用直接选择排序法用的时间为%f秒;",time);
fp=fopen("直接选择排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTBubbleSort(inta[],intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
fclose(fp);return(time);
doubleTBubbleSort(inta[],intp)
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);BubbleSort(b,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用冒泡排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("冒泡排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
BubbleSort(b,p);
printf("\n用冒泡排序法用的时间为%f秒;",time);
fp=fopen("冒泡排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTheapsort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
doubleTheapsort(inta[],intn,intp)
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);heapsort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用堆排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("堆排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
heapsort(b,N,p);
printf("\n用堆排序法用的时间为%f秒;",time);
fp=fopen("堆排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}doubleTquicksort(inta[],intn,intp){inti;intb[N];for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
doubleTquicksort(inta[],intn,intp)
for(i=0;ib[i]=a[i];LARGE_INTEGERm_liPerfFreq={0};QueryPerformanceFrequency(&m_liPerfFreq);LARGE_INTEGERm_liPerfStart={0};QueryPerformanceCounter(&m_liPerfStart);quicksort(b,N,p);LARGE_INTEGERliPerfNow={0};QueryPerformanceCounter(&liPerfNow);doubletime=liPerfNow.QuadPart-m_liPerfStart.QuadPart;time/=m_liPerfFreq.QuadPart;if(p!=7){Disp(b);getchar();}printf("\n用快速排序法用的时间为%f秒;",time);FILE*fp;fp=fopen("快速排序.txt","w");for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
quicksort(b,N,p);
printf("\n用快速排序法用的时间为%f秒;",time);
FILE*fp;fp=fopen("快速排序.txt","w");
for(i=0;ifprintf(fp,"%d",b[i]);fclose(fp);return(time);}voidBubleSort(doublea[])//时间数组的冒泡排序{inti,j;doubletemp;for(i=1;i<7;i++){for(j=5;j>=i;j--)if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
voidBubleSort(doublea[])//时间数组的冒泡排序
inti,j;
doubletemp;
for(i=1;i<7;i++)
for(j=5;j>=i;j--)
if(a[j+1]{temp=a[j+1];a[j+1]=a[j];a[j]=temp;}}}voidmenu(){printf("**************欢迎来到排序系统!****************\n");printf("**************(1)---直接插入排序******************\n");printf("**************(2)---希尔排序******************\n");printf("**************(3)---直接选择排序******************\n");printf("**************(4)---冒泡排序******************\n");printf("**************(5)---快速排序******************\n");printf("**************(6)---堆排序******************\n");printf("**************(7)---时间效率比较******************\n");printf("**************(8)---显示随机数******************\n");printf("**************(0)---退出******************\n");printf("****************************************************\n");printf("\n====>请在上述序号中选择一个并输入:");}voidmain(){inti,p,a[N];srand((int)time(NULL));/*随机种子*/for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
temp=a[j+1];
a[j+1]=a[j];
voidmenu()
printf("**************欢迎来到排序系统!
****************\n");
printf("**************
(1)---直接插入排序******************\n");
(2)---希尔排序******************\n");
printf("**************(3)---直接选择排序******************\n");
printf("**************(4)---冒泡排序******************\n");
printf("**************(5)---快速排序******************\n");
printf("**************(6)---堆排序******************\n");
printf("**************(7)---时间效率比较******************\n");
printf("**************(8)---显示随机数******************\n");
printf("**************(0)---退出******************\n");
printf("****************************************************\n");
printf("\n====>请在上述序号中选择一个并输入:
");
voidmain()
inti,p,a[N];
srand((int)time(NULL));/*随机种子*/
for(i=0;ia[i]=rand()%50000+1;while(1){system("cls");menu();
a[i]=rand()%50000+1;
while
(1)
menu();
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1