Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
max-heapify(A,i){
index_of_left_child = left(i);
index_of_right_child = right(i);
heap_size = number_of_elements_in_heap(A)
if((index_of_left_child <= heap_size) && (A[index_of_left_child] > A[i]))
largest = index_of_left_child
else
largest = i
if((index_of_right_child <= heap_size) && (A[index_of_right_child] > A[i]))
largest = index_of_right_child
if(i != largest)
exchange(A[i], A[largest])
max-heapify(A,largest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment