c – 增加堆栈不工作
发布时间:2020-12-16 09:31:04 所属栏目:百科 来源:网络整理
导读:如何使用Bloodshed Dev C或Code :: Block正确增加程序可用的堆栈?我正在运行简单的泡泡和快速排序工作,但当我在Code :: Block中更改堆栈(发现如何超过 here)它使我的程序崩溃更快,尽管使用了超过建议的空间.最初,程序在排序64K随机整数时崩溃(使用rand()函
如何使用Bloodshed Dev C或Code :: Block正确增加程序可用的堆栈?我正在运行简单的泡泡和快速排序工作,但当我在Code :: Block中更改堆栈(发现如何超过
here)它使我的程序崩溃更快,尽管使用了超过建议的空间.最初,程序在排序64K随机整数时崩溃(使用rand()函数).现在,它崩溃在32K.我得到错误:进程返回-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,r_index) + pivot + a_quick(right,r_index,r_index); } 其余代码只是生成具有32,64和128 k条目的数组和向量,使用上面的代码对它们进行排序并返回时间.那部分我很确定我没搞砸 我的主要基本上就是 start = clock(); a_quick(array1,32000); end = clock(); cout << "nQuick SorttArrayt32000t" << ((double) end - start)/CLOCKS_PER_SEC << " secondsn"; 一遍又一遍地 解决方法
除非你为一个内存受限的嵌入式环境编程,否则我怀疑你的排序实现中有一个导致堆栈溢出的递归错误.除非您正在处理真正庞大的(许多GB)数组,否则不必更改堆栈大小.
小心发布一些代码? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- swift3 – 为iOS8创建Launch Screen.xib(… iOS11,Swift 4和
- 使用PostgreSQL数据库做PHP开发
- 常用工具的依赖
- flashback六大技术之flashback version query
- objective-c – 如何仅更改NSTextView中整个样式文本的字体
- vb.net – MS Access网络共享速度慢
- AJAX 之 IE缓存惹的祸 +Math.random() 《随机数》
- 在C#中更新对象时会话对象发生更改
- ruby-on-rails – 使用Ruby on Rails Twitter Gem在twitter
- c – 如何为枚举类编写’using’语句?