MAX-HEAPIFY代码效率较高,但第10行中的递归调用可能例外,它可能使某些编译器产生低效的代码,请用循环控制结构取代递归,重写MAX-HEAPIFY。
Max_Heapify(A,idx,max) left = 2*idx right = 2*idx if(left<max and A[left]>A[idx]) then largest = left else largest = idx if(right < max and A[right]>A[largest]) then largest = ritht if(largest != idx) then exchange A[largest] with A[idx] Max_Heapify(A,largest,max) end