如何使用 Bloodshed Dev C++ 或 Code::Block 正确增加程序可用的堆栈?我正在运行简单的气泡和快速排序,但是当我在 Code::Block 中更改堆栈时(了解如何在这里)它使我的程序崩溃得更快,尽管使用的空间比建议的空间多得多。最初,程序在对 64K 的随机整数进行排序时崩溃(使用该rand()
函数)。现在,它在 32K 时崩溃。我收到错误:Process returned -1073741571 (0xC00000FD)
假设我做对了,该程序实际上运行得更快而无需更改堆栈。gcc -Wl,--stack,1099511627776
我不知道如何在 Dev C++ 中改变它
我应该怎么办?有没有办法改变代码本身的堆栈?这是我用于冒泡和快速排序的代码。每个有两个:一个是向量,另一个是数组。我认为是冒泡排序。应该是正确的。快速排序,我不太确定。抱歉,如果有点乱
vector <int> v_bubble(vector <int> array){
// Vector Bubble Sort
if (array.size() < 2){
return array;
}
int s = 1;
while (s){
s = 0;
for (unsigned int x = 0; x < (array.size() - 1); x++){
if (array[x] > array[x + 1]){
int t = array[x];
array[x] = array[x + 1];
array[x + 1] = t;
s = 1;
}
}
}
return array;
}
void a_bubble(int array[], int size){
// Array Bubble Sort
int s = 1;
while (s){
s = 0;
for (int x = 0; x < (size - 1); x++){
if (array[x] > array[x + 1]){
int t = array[x];
array[x] = array[x + 1];
array[x + 1] = t;
s = 1;
}
}
}
}
vector <int> v_quick(vector <int> array){
//Vector Quick Sort
if (array.size() < 2){
return array;
}
vector <int> left;
vector <int> right;
int p_location = array.size() / 2 - 1;
int pivot = array[p_location];
for(unsigned int x = p_location; x < array.size() - 1; x++){
array[x] = array[x + 1];
}
array.pop_back();
for(unsigned int x = 0; x < array.size(); x++){
if (array[x] <= pivot) {
left.push_back(array[x]);
}
else if (array[x] > pivot){
right.push_back(array[x]);
}
}
vector <int> p;
p.push_back(pivot);
return combine(combine(v_quick(left), p), v_quick(right));
}
int a_quick(int array[], int size, int l_index = -1, int r_index = -1){
//Array Quick Sort
if (size < 2){
return array[size];
}
array[size] = array[size];
int left[size];
int right[size];
l_index = 0;
r_index = 0;
int p_location = size / 2 - 1;
int pivot = array[p_location];
for(int x = p_location; x < size - 1; x++){
array[x] = array[x + 1];
}
size--;
for(unsigned int x = 0; x < size; x++){
if (array[x] <= pivot) {
left[l_index] = array[x];
l_index++;
}
else if (array[x] > pivot){
right[r_index] = array[x];
r_index++;
}
}
return a_quick(left, l_index, l_index, r_index) + pivot + a_quick(right, r_index, l_index, r_index);
}
其余代码只是简单地生成具有 32、64 和 128 k 条目的数组和向量,使用上述代码对它们进行排序并返回时间。那部分我很确定我没有搞砸
我的主要基本上只是
start = clock();
a_quick(array1, 32000);
end = clock();
cout << "\nQuick Sort\tArray\t32000\t" << ((double) end - start)/CLOCKS_PER_SEC << " seconds\n";
一遍又一遍地