We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3bb91cc + 7ec5b81 commit 6ce5972Copy full SHA for 6ce5972
src/main/kotlin/codecollection/algorithms/SelectionSort.kt
@@ -1,7 +1,5 @@
1
package codecollection.algorithms
2
3
-import java.util.Collections
4
-
5
fun selectionSort(list: List<Int>): List<Int> {
6
if (list.size <= 1) return list
7
val result = list.toMutableList()
@@ -10,7 +8,7 @@ fun selectionSort(list: List<Int>): List<Int> {
10
8
for (j in i + 1 until result.size) {
11
9
if (result[j] < result[minIndex]) minIndex = j
12
}
13
- if (minIndex != i) Collections.swap(result, minIndex, i)
+ if (minIndex != i) result[minIndex] = result[i].also { result[i] = result[minIndex] }
14
15
return result
16
0 commit comments