玄学报错
  • 板块学术版
  • 楼主cmaths
  • 当前回复14
  • 已保存回复14
  • 发布时间2020/6/8 21:05
  • 上次更新2023/11/7 00:58:27
查看原帖
玄学报错
300098
cmaths楼主2020/6/8 21:05
#include <cstdio>
#include <algorithm>
#include <ctime>
#include <cstdlib>

int n = 10000000, a[n];
void qsort(int l, int r)
{
	if (l >= r)
		return;
	int t = a[rand() % n], i = l, j = r;
	while (i <= j)
	{
		while (a[i] < t)
			i++;
		while (a[j] > t)
			j--;
		if (i <= j)
		{
			std::swap(a[i], a[j]);
			i++;
			j--;
		}
	}
	qsort(l, j);
	qsort(i, r);
}
int main ()
{
	srand(time(0));
	clock_t s, e;
	double use;
	for (int i = 0; i < n; i++)
		a[i] = rand() % 1000;
	s = clock();
	qsort(1, n - 1);
	e = clock();
	use = (e - s) / CLOCKS_PER_SEC;
	printf("用时:%lfs", use);
	return 0;
}

2020/6/8 21:05
加载中...