Created
July 13, 2017 14:57
-
-
Save vaidehijoshi/6536e03b81e93a78c56537117791c3f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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