Heapify(A,i)

Notice that if A[left(i)] A[i] or if A[right(i)] A[i] or both (take largest) then swap and recurse until recursion bottoms out at bottom of heap.