三种直接插入排序方法见博客https://blog.csdn.net/weixin_53032617/article/details/124046994
下列代码是测试这三种排序方法的效率
#include "stdio.h"
#include "time.h"
void TestSortEffiency()
{
int n = 10000;
int *a = (int *)malloc(sizeof(int) * n);
int* a1 = (int*)malloc(sizeof(int) * n);
int* a2 = (int*)malloc(sizeof(int) * n);
srand(time(0));
for (int i = 0; i < n; i++)
{
a[i] = rand();
a1[i] = a[i];
a2[i] = a[i];
}
time_t start = clock();
InsertSort(a, 0, n);
time_t end = clock();
start = clock();
InsertSort_1(a1, 0, n);
end = clock();
start = clock();
InsertSort_2(a2, 0, n);
end = clock();
printf("InsertSort:%u\n", end - start);
printf("InsertSort_1:%u\n", end - start);
printf("InsertSort_2:%u\n", end - start);
}
int main()
{
int ar[] = {13,37,34,78,90,88,12 };
int n = sizeof(ar) / sizeof(ar[0]);
PrintfArray(ar, 0, n);
InsertSort_1(ar, 0, n);
InsertSort_2(ar, 0, n);
PrintfArray(ar, 0, n);
TestSortEffiency();
}