Skip to content

Instantly share code, notes, and snippets.

@vaidehijoshi
Created July 13, 2017 14:57
Show Gist options
  • Save vaidehijoshi/6536e03b81e93a78c56537117791c3f1 to your computer and use it in GitHub Desktop.
Save vaidehijoshi/6536e03b81e93a78c56537117791c3f1 to your computer and use it in GitHub Desktop.
function heapSort(array) {
// Build our max heap.
buildMaxHeap(array);
// Find last element.
lastElement = array.length - 1;
// Continue heap sorting until we have
// just one element left in the array.
while(lastElement > 0) {
swap(array, 0, lastElement);
heapify(array, 0, lastElement);
lastElement -= 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment