最近,在学习郝斌老师的数据结构时,马上学完了,结果一个代码搞得我满脸懵。最后是怎么解决的呢?我第一次是在vs上写的,说栈溢出,然后到dev上,一点问题没有。
测试代码【放在vs和dev上很有意思,另外,今天是七夕节,祝大家早日脱单】
#include <stdio.h>
void FastSort(int* p, int low, int high);
int FindPosition(int* p, int low, int high);
int main()
{
int a[7] = { 5,2,0,1,3,1,4 };
printf("该数组的长度为:%d\n", 7);
FastSort(a, 0, 7);
for (int i = 0; i < 7; i++)
{
printf("%d ", a[i]);
}
return 0;
}
void FastSort(int* p, int low, int high)
{
int pos = 0;
if(low < high)
{
pos = FindPosition(p, low, high);
FastSort(p, low, pos - 1);
FastSort(p, pos+1, high);
}
}
int FindPosition(int* p, int low, int high)
{
//该函数包含了查找元素最终位置的过程 以及 具体的排序手法
int val = p[low];
while (low < high)
{
while (low < high && p[high] >= val)
--high;
p[low] = p[high];
while (low < high && p[low] <= val)
++low;
p[high] = p[low];
}
p[low] = val;
return high;
}
这段代码的问题出就出在了:在vs里,软件自己给你限制了栈的大小,而你的程序需要的栈超出了它的限制。
解决办法:vs主界面里 “project->配置属性->c/c++->代码生成->基本运行时检查 设置为默认值
参考链接:https://www.cnblogs.com/flysnail/archive/2011/09/21/2184114.html
好了,没有了