next up previous
Next: Recursive Analysis Up: CSE 2320: Algorithms and Previous: Maintaining the Heap Property

Pseudocode

Heapify(A,i)
1
$\;\;\;\;\;$l = left(i)
2
$\;\;\;\;\;$r = right(i)
3
$\;\;\;\;\;$if l $\leq$ HeapSize(A) and A[l] > A[i]
4
$\;\;\;\;\;$then largest = l
5
$\;\;\;\;\;$else largest = i
6
$\;\;\;\;\;$if r $\leq$ HeapSize(A) and A[r] > A[largest]
7
$\;\;\;\;\;$then largest = r
8
$\;\;\;\;\;$if largest $\neq$ i
9
$\;\;\;\;\;$then swap(A[largest], A[i])
10
$\;\;\;\;\;$ $\;\;\;\;\;$Heapify(A, largest)



Copyright © 1998 The University of Texas at Arlington