Selection sort

An example of the implementation of the selection sort algorithm.

Input data

original data 	 1, 9, 3, 5, 14, 2, 0, 4, 10, 6

Insertion sort

fun insertionSort(data: Array<Int>) {
    for (j in 1 until data.size) {
        val key = data[j]
        var i = j - 1
        while (i >= 0 && data[i] > key) {
            data[i + 1] = data[i]
            i--
        }
        data[i+1] = key
    }
}

Output data

insertionSort 	 0, 1, 2, 3, 4, 5, 6, 9, 10, 14