stdlib: Add mutableList.sort function
This commit is contained in:
@@ -258,17 +258,17 @@ private fun MutableCollection<*>.retainNothing(): Boolean {
|
|||||||
/**
|
/**
|
||||||
* Sorts elements in the list in-place according to their natural sort order.
|
* Sorts elements in the list in-place according to their natural sort order.
|
||||||
*/
|
*/
|
||||||
@FixmeSorting
|
public fun <T : Comparable<T>> MutableList<T>.sort(): Unit = sortWith(Comparator<T> { a: T, b: T -> a.compareTo(b) })
|
||||||
public fun <T : Comparable<T>> MutableList<T>.sort(): Unit {
|
|
||||||
TODO()
|
|
||||||
//if (size > 1) java.util.Collections.sort(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts elements in the list in-place according to the order specified with [comparator].
|
* Sorts elements in the list in-place according to the order specified with [comparator].
|
||||||
*/
|
*/
|
||||||
@FixmeSorting
|
|
||||||
public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
|
public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
|
||||||
TODO()
|
if (size > 1) {
|
||||||
//if (size > 1) java.util.Collections.sort(this, comparator)
|
val it = listIterator()
|
||||||
|
for (v in toTypedArray().apply { sortWith(comparator) }) {
|
||||||
|
it.next()
|
||||||
|
it.set(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user