Created
March 5, 2018 22:30
-
-
Save kalub92/b9244a9a3d0e9cd17c0711a9ef75d1f1 to your computer and use it in GitHub Desktop.
This file contains 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
mutating private func heapifyDown() { | |
var index = 0 | |
while hasLeftChild(index) { | |
var smallerChildIndex = getLeftChildIndex(index) | |
if hasRightChild(index) && rightChild(index) < leftChild(index) { | |
smallerChildIndex = getRightChildIndex(index) | |
} | |
if items[index] < items[smallerChildIndex] { | |
break | |
} else { | |
swap(indexOne: index, indexTwo: smallerChildIndex) | |
} | |
index = smallerChildIndex | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment