fun insertionSort(array: MutableList<Int>) {
for (i in 1 until array.count()) {
var j = i
while (j > 0 && array[j] < array[j - 1]) {
val tmp = array[j]
array[j] = array[j - 1]
array[j - 1] = tmp
j--
}
}
}
fun main() {
val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
insertionSort(array)
println(array)
}
ZnVuIGluc2VydGlvblNvcnQoYXJyYXk6IE11dGFibGVMaXN0PEludD4pIHsKICAgIGZvciAoaSBpbiAxIHVudGlsIGFycmF5LmNvdW50KCkpIHsKICAgICAgICB2YXIgaiA9IGkKICAgICAgICB3aGlsZSAoaiA+IDAgJiYgYXJyYXlbal0gPCBhcnJheVtqIC0gMV0pIHsKICAgICAgICAgICAgdmFsIHRtcCA9IGFycmF5W2pdCiAgICAgICAgICAgIGFycmF5W2pdID0gYXJyYXlbaiAtIDFdCiAgICAgICAgICAgIGFycmF5W2ogLSAxXSA9IHRtcAogICAgICAgICAgICBqLS0KICAgICAgICB9CiAgICB9Cn0KCmZ1biBtYWluKCkgewogICAgdmFsIGFycmF5ID0gbXV0YWJsZUxpc3RPZig3LCAzLCAwLCAxLCA1LCAyLCA1LCAxOSwgMTAsIDUpCgogICAgaW5zZXJ0aW9uU29ydChhcnJheSkKCiAgICBwcmludGxuKGFycmF5KQp9
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]