排序性能测试比较
来源:互联网 发布:java 获取当前locale 编辑:程序博客网 时间:2024/05/16 09:03
用了头文件“sort.h” 附链接: http://blog.csdn.net/hit_fantasy/article/details/8739985
用rand()生成随机数组,然后用start=clock(); XXXXSort(a,len); finish=clock();来计时。
基数排序没有做,不知道怎么确定基数。
#include <iostream>#include <time.h>#include <cstdlib>#include "sort.h"#include <conio.h>#include <cstdio>using namespace std;void menu(){ cout<<"1.bubbleSort\n\n"; cout<<"2.selectSort\n\n"; cout<<"3.insertSort\n\n"; cout<<"4.shellSort\n\n"; cout<<"5.mergeSort\n\n"; cout<<"6.quickSort\n\n"; cout<<"7.radixSort\n\n"; cout<<"8.heapSort\n\n"; cout<<"9.exit\n\n";}void sortTime(){//creat the test array srand(time(NULL)); //length 99999 cout<<"please input the length of the test array."<<endl; int len; cin>>len; int *a=new int[len]; /* cout<<"please input max element in the array.(to ensure the scope)"<<endl; int scope; cin>>scope;*/ for(int i=0;i<len;i++) { a[i]=rand(); //a[i]=rand()%scope+1; }//count the time clock_t start,finish; double duration; cout<<"\n\nPlease chose 1-9 as follow.\n\n"; menu(); char in; cin>>in; switch(in) { case'1': cout<<"bubbleSort:\n"; start=clock(); bubbleSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'2': cout<<"selectSort:\n"; start=clock(); selectSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'3': cout<<"insertSort:\n"; start=clock(); insertSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'4': cout<<"shellSort:\n"; start=clock(); shellSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'5': cout<<"mergeSort:\n"; start=clock(); mergeSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'6': cout<<"quickSort:\n"; start=clock(); quickSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'7': break; case'8': cout<<"heapSort:\n"; start=clock(); heapSort(a,len); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("End! it costs %.3f seconds totally.\n",duration); system("pause"); break; case'9': exit(0); } delete []a;}int main(){ // freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while(1) { sortTime(); } return 0;}
- 排序性能测试比较
- Stream性能比较测试
- 排序算法性能比较
- 排序算法性能比较
- 排序算法性能比较
- 各种排序性能比较
- 排序算法性能比较
- 排序算法性能比较
- 排序算法性能比较
- SSD硬盘性能测试比较
- MySQL性能比较测试(转)
- 简单排序及其性能比较
- 内排序的性能比较
- 各种排序算法性能比较
- 各种排序算法性能比较
- 各种排序算法性能比较。
- 补充排序的性能比较
- 常用排序算法性能比较
- 各种排序实现
- sql查询表结构,过程,视图,主键,外键,约束
- ORACLE通过netca配置监听遇到 TNS-04415错误
- Asp.net Form Action
- 看看培训中心培训Android系统开发培训都讲些啥
- 排序性能测试比较
- 从索引技术谈数据库查询索引建立和查询条件书写
- .h头文件 .lib库文件 .dll动态链接库文件关系
- vs2008快捷键极其技巧
- 浅谈为什么Java接口中不允许定义变量
- MySQL表字段设置默认值(图文教程及注意细节)
- asp.net repeater 循环嵌套
- 一个网上找到的,在Grid中嵌套Grid的示例:Nested Grids Example
- Linux_CPU寄存器简介