StalinSort

Stalin Sort.

Removes any element that is out of order — rather than sorting them, it simply "purges" them. The result is a sorted array, but potentially shorter.

Time complexity: O(n) Space complexity: O(n) for the filtered result

WARNING: Destructive — elements that break ordering are permanently removed.

Functions

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

Sorts (and purges) a generic array using natural ordering.

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

Sorts (and purges) a generic array using a custom comparator.