QuickSortIterative

Quick Sort (Iterative).

An iterative variant of Quick Sort that uses an explicit stack instead of recursion, avoiding stack overflow on large inputs. Achieves O(n log n) average-case time with O(log n) stack space. Uses median-of-three pivot selection to mitigate worst-case O(n²).

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.