6.2 维护堆的性质
l = left(i)r = right(i)if l <= A.heap-size and A[l] > A[i]largest = lelse largest = iif r <= A.heap-size and A[r] > A[largest]largest = rif largest != iexchange A[i] with A[largest]maxHeapify(A, largest)
6.3 建堆
A.heap-size = A.lengthfor i = Math.floor(A.length / 2) downto 1maxHeapify(A, i)
6.4 堆排序算法
buildMaxHeap(A)for i = A.length downto 2exchange A[1] with A[i]A.heap-size = A.heap-size - 1maxHeapify(A, 1)
