我正在爲作業實現堆排序。我們必須按照她在課堂上使用她的僞代碼的方式來做,否則我們不會得到信任。堆排序錯誤:圍繞變量堆棧損壞?
即時得到一個運行時錯誤:圍繞變量「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;
}