qq_24861865 于 2015.06.06 11:45 提问

#include
#include
#include
#include"sort.h"
using namespace std;
int main()
{
int choice, n, i, j;
DWORD start, end;
while(1)
{
cout << "输入数据的方式：" << endl;
cout << "1、手动输入" << endl;
cout << "2、系统自动产生" << endl;
cout << "输入方式序号：" << endl;
cin >> choice;

``````    if (choice == 1)
{
cout << "排序的元素个数：" << endl;
cin >> n;
int *a = new int[n];
int *b = new int[n];
int *temp = new int[n];
cout << "要排序的元素：" << endl;

for (i = 0; i < n; i++)
{
cin >> a[i];
b[i] = a[i];
}

cout << "快排结果：" << endl;
Quicksort(a, 0, n - 1);

for (i = 0; i < n; i++)
cout << a[i] << " ";

cout << endl;
cout << "归并结果：" << endl;
Mergesort(b, 0, n - 1);

for (i = 0; i < n; i++)
cout << b[i] << " ";

cout << endl;
}

else if (choice == 2)
{
cout << "下面将随机产生10组数据：" << endl;
for (i = 1; i <= 10; i++)
{
cout << "#" << i << endl;
int *a = new int[10000 * i];
int *b = new int[10000 * i];
int *temp = new int[10000 * i ];

for (j = 0; j < 10000 * i; j++)
{
a[j] = rand() % 100000;
b[j] = a[j];
}

start = GetTickCount();
Quicksort(a, 0, 10000 * i - 1);
end = GetTickCount();
cout << "快速排时间：" << end - start << "ms" << endl;
start = GetTickCount();
Mergesort(b, 0, 10000 * i - 1);
end = GetTickCount();
cout << "归并排时间：" << end - start << "ms" << endl;
}
}
else
break;
}
system("pause");
return 0;

``````

4个回答

qq_24861865   2015.06.06 11:50

qq_24861865   2015.06.06 11:50

caozhy      2015.06.06 12:02

qq_24861865 另外就是我重装了一次vs，然后结果运行正确，关掉再重启就继续出错了
2 年多之前 回复
qq_24861865 试了，然后除了运行时间变慢之外，结果依旧，只有固定从0，15，16，31，32中产生，而且很乱
2 年多之前 回复
zc1107473010   2015.06.06 13:23

for (i = 1; i <= 10; i++)
{

cout << "#" << i << endl;
int *a = new int[10000 * i];
int *b = new int[10000 * i];
int *temp = new int[10000 * i ];

``````        for (j = 0; j < 10000 * i; j++)
{
a[j] = rand() % 100000;
b[j] = a[j];
}

start = GetTickCount();
Quicksort(a, 0, 10000 * i - 1);
end = GetTickCount();
cout << "快速排时间：" << end - start << "ms" << endl;
start = GetTickCount();
Mergesort(b, 0, 10000 * i - 1);
end = GetTickCount();
cout << "归并排时间：" << end - start << "ms" << endl;
delete []a;
delete []b;
}
``````