Input data
original data 1, 9, 3, 5, 14, 2, 0, 4, 10, 6
Selection sort
fun selectionSort(data: Array<Int>) {
for (i in data.indices) {
var minIndex = i
for (j in i until data.size) {
if (data[j] < data[minIndex]) {
minIndex = j
}
}
data.swap(i, minIndex)
}
}
Output data
insertionSort 0, 1, 2, 3, 4, 5, 6, 9, 10, 14