array
between from
and to
indicesWorst case: O(n lg n), average: O(n lg n)
var a = [5, 2, 3, 1, 4]
default_comparator.heap_sort(a, 0, a.length - 1)
assert a == [1, 2, 3, 4, 5]
# Heap-sort `array` between `from` and `to` indices
# Worst case: O(n lg n), average: O(n lg n)
#
# var a = [5, 2, 3, 1, 4]
# default_comparator.heap_sort(a, 0, a.length - 1)
# assert a == [1, 2, 3, 4, 5]
fun heap_sort(array: Array[COMPARED], from, to: Int) do
var size = build_heap(array)
for j in [from..to[ do
array.swap_at(0, size)
size -= 1
heapify(array, 0, size)
end
end
lib/core/collection/sorter.nit:217,2--230,4