June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,11 +1,10 @@
|
|||
fun quicksort(list: List<Int>): List<Int> {
|
||||
fun <T : Comparable<T>> quicksort(list: List<T>): List<T> {
|
||||
if (list.isEmpty()) return emptyList()
|
||||
|
||||
val head = list.first()
|
||||
val tail = list.takeLast(list.size - 1)
|
||||
|
||||
val less = quicksort(tail.filter { it < head })
|
||||
val high = quicksort(tail.filter { it >= head })
|
||||
val (less, high) = tail.partition { it < head }
|
||||
|
||||
return less + head + high
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue