标签:style blog http color io ar for sp div
插入排序:
#include<stdio.h> #include<time.h> #include<stdlib.h> int main() { /*生成随机数组*/ srand(time(0));//随机种子 int arr[10000]; int n = sizeof(arr) / 4; for (int i = 0; i < n; i++){ arr[i] = 100 * rand() / RAND_MAX; } double start, end; start = clock();//取开始时间 /*选择排序*/ int i = 1; for (i; i < n; i++){ for (int j=i; j >-1; j--){ if (arr[j] < arr[j - 1]){ int t = arr[j-1]; arr[j-1] = arr[j]; arr[j] = t; } } } /*输出*/ for (int k = 0; k < n; k++) { printf("%3d_", arr[k]); } end = clock();//取结束时间 printf("%f seconds\n", (end - start) / CLOCKS_PER_SEC);//计算程序运行时间 }
c与python选择排序性能比较:
标签:style blog http color io ar for sp div
原文地址:http://www.cnblogs.com/dingblog/p/4052822.html