function heapSort(a, count) { var int start := count ÷ 2 - 1, end := count - 1 while start = 0 sift(a, start, count) start := start - 1 while end > 0 swap(a[end], a[0]) sift(a, 0, end) end := end - 1 } function sift(a, start, count) { var int root := start, child while root * 2 + 1 < count { child := root * 2 + 1 if child < count - 1 and a[child] < a[child + 1] child := child + 1 if a[root] < a[child] swap(a[root], a[child]) root := child else return } }