HeapSort

Heap Sort.

Builds a max-heap from the array, then repeatedly extracts the maximum element to produce a sorted array in-place.

Time complexity : O(n log n) in all cases Space complexity: O(1)

Functions

Link copied to clipboard
fun <T : Comparable<T>> sort(array: Array<T>)

Sorts the array in ascending natural order.

fun sort(array: IntArray)

Sorts an IntArray in ascending order.

fun <T> sort(array: Array<T>, comparator: Comparator<T>)

Sorts the array using the given comparator.