比较C++和C实现直接插入排序和二分插入排序效率!
注:之前没有发现这其实是两个不同算法,现在更正下。
下面用C++实现二分插入排序和C实现直接插入排序,明天会继续测试下C++实现直接插入排序和C实现二分插入排序
下面是几次的输出结果:
(C)Total seconds time taken by CPU: 119.920000
(C++)seconds time: 14.92
(C)Total seconds time taken by CPU: 118.190000
(C++)seconds time: 14.53
(C)Total seconds time taken by CPU: 118.660000
(C++)seconds time: 14.52
C实现直接插入排序代码:
(linux下编译 g++ test.cpp -o test执行./test)
#include <stdio.h>
#include <time.h>
#define GETCOUNT(x) (sizeof(x) / sizeof((x)[0]))
void InsertionSort(int *a, int n) {
int tmp,j;
for(int i = 1; i < n; ++i) {
tmp = a[i];
j