测试不同排序方法的效率

三种直接插入排序方法见博客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();
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值