function sift(a, start, count) {
var int root := start, child
while root * 2 + 1 < count {
child := root * 2 + 1 // Ignore this--you can
access a node's children much easier! :)
if child < count - 1 and a[child] < a[child + 1] // Choose the larger of the sons, if there are two
child := child + 1
if a[root] < a[child] // If root node is too small...
swap(a[root], a[child]) // Swap it with the previously determined larger son
root := child // ...and keep track of where it is now.
// This way, on the next loop iteration the subtree that has the just-moved node as its root will be sifted into
// Another possible way here would have been to use recursion
else
return
}
}