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