测sort与qsort耗时
来源:互联网 发布:网络教育68所学校 编辑:程序博客网 时间:2024/06/14 04:17
//测试sort与qsort耗时
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <algorithm>using namespace std;int cmp( const void *a , const void *b ){ int *c=(int *)a; //(int*)是强制类型转换 int *d=(int *)b; return *c-*d;}int a[100000005],b[100000006];int main() { int g=1; srand((int)time(NULL));//产生随机因子for(int i=0; i<100000000; i++){ int j=1+rand()%100000000;//获取随机数 if(g==1) g=-1; else g=1; j=j*g; a[i]=b[i]=j;} clock_t start,finish; double TheTimes; start=clock(); sort(a,a+100000000); finish=clock(); TheTimes=(double)(finish-start)/CLOCKS_PER_SEC; printf("sort耗时 %f秒。\n",TheTimes); start=clock(); qsort(b,100000000,sizeof(int),cmp); finish=clock(); TheTimes=(double)(finish-start)/CLOCKS_PER_SEC; printf("qsort耗时 %f秒。\n",TheTimes); return 0; }
阅读全文
0 0
- 测sort与qsort耗时
- sort与qsort函数
- sort与qsort
- qsort与sort
- qsort与sort
- qsort与sort
- sort与qsort
- sort()与qsort()
- sort 与 qsort
- std::sort与qsort
- qsort与sort 排序
- sort与qsort函数
- qsort与sort
- sort 与Qsort 排序
- qsort与sort
- sort与qsort
- sort与qsort
- sort 与 qsort
- String类中replaceAll方法不能替换美元符号$的问题解决
- Servlet学习笔记 -- day02 Request
- 接口
- 走进Vue.js
- IDEA使用--字体、编码和基本设置
- 测sort与qsort耗时
- define与const 比较
- 四元数姿态的梯度下降法推导和解读
- 笔记2--html基础知识
- HDU--1018--Big number!(计算阶乘结果的位数)
- 1028. 人口普查(20)
- ecmall widgets 挂件开发详解
- 利用ServletContext实现页面访问量的统计
- 传智播客Python就业班