heapSort(A): # buildHeap for i ← N/2 - 1 downto 0: downHeap(A, i) heapSize ← N while heapSize ≥ 2: swap(A[0], A[heapSize-1]) heapSize-- downHeap(A, 0) # heapSizeの範囲でダウンヒープ