QuickSort

Quick Sort.

A divide-and-conquer algorithm that selects a pivot element and partitions the array around it, recursively sorting each partition.

Pivot selection uses median-of-three to reduce the probability of hitting the O(n²) worst case on already-sorted or reversed input.

Time complexity : O(n log n) average, O(n²) worst case Space complexity: O(log n) stack space

The partition methods are internal so that IntroSort can reuse them directly rather than duplicating the logic.

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.