3 ms·
> Quicksort is a mouthful to explain in detail Don't know about that, this is not efficent but "explains" quicksort in general: fun <T : Comparable<T>> qu
by sorokod 7y ago
> Quicksort is a mouthful to explain in detail
Don't know about that, this is not efficent but "explains" quicksort in general:
fun <T : Comparable<T>> quickSort(list: List<T>): List<T> =
with(list) {
if (size < 2) this
else {
val pivot = first()
val (smaller, greater) = drop(1).partition { it <= pivot }
quickSort(smaller) + pivot + quickSort(greater)
}
}