Skip to content

Commit 6ce5972

Browse files
authored
Merge branch 'main' into demonstrate-data-classes
2 parents 3bb91cc + 7ec5b81 commit 6ce5972

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package codecollection.algorithms
22

3-
import java.util.Collections
4-
53
fun selectionSort(list: List<Int>): List<Int> {
64
if (list.size <= 1) return list
75
val result = list.toMutableList()
@@ -10,7 +8,7 @@ fun selectionSort(list: List<Int>): List<Int> {
108
for (j in i + 1 until result.size) {
119
if (result[j] < result[minIndex]) minIndex = j
1210
}
13-
if (minIndex != i) Collections.swap(result, minIndex, i)
11+
if (minIndex != i) result[minIndex] = result[i].also { result[i] = result[minIndex] }
1412
}
1513
return result
1614
}

0 commit comments

Comments
 (0)