Implement reverse of lists, fixes few tests.

This commit is contained in:
Nikolay Igotti
2017-02-17 12:44:06 +03:00
parent 5d004c06bf
commit c0f9c9fd5d
@@ -958,10 +958,18 @@ public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T>
/**
* Reverses elements in the list in-place.
*/
@Fixme
public fun <T> MutableList<T>.reverse(): Unit {
//java.util.Collections.reverse(this)
TODO()
val median = size / 2
var leftIndex = 0
var rightIndex = size - 1
while (leftIndex < median) {
val tmp = this[leftIndex]
this[leftIndex] = this[rightIndex]
this[rightIndex] = tmp
leftIndex++
rightIndex--
}
}
/**