我正在为一项任务实施堆排序。我们必须像她在课堂上用她的伪代码那样做,否则我们不会得到荣誉。
我收到运行时错误:围绕变量“heapArray”的堆栈已损坏。我玩了调试器,但仍然无法找出导致错误的原因。我很确定这与我在 HeapSort() 函数中的 For 循环有关。任何人都可以帮忙吗?
void HeapSort(int heapArray[])
{
int heap_size = SIZE;
int n = SIZE;
int temp;
Build_Max_Heap(heapArray);//function not implemented, only declared for compile
for(int i = n; i >=2; i--) //***I think error coming from something in here
{
temp = heapArray[1];
heapArray[1] = heapArray[i];
heapArray[i] = temp;
heap_size = heap_size-1;
Max_Heapify(heapArray,1);//function not implemented, only declared for compile
}
return;
}
int main()
{
int heapArray[SIZE] = { 5 ,99, 32, 4, 1, 12, 15 , 8, 13, 55 };
HeapSort(heapArray);
cout << endl;
return 0;
}