fun gnomeSort(array: MutableList<Int>) {
var i = 0
while (i < array.count()) {
if (i == 0 || array[i] >= array[i - 1]) {
i++
} else {
val tmp = array[i]
array[i] = array[i - 1]
array[i - 1] = tmp
i--
}
}
}
fun main() {
val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
gnomeSort(array)
println(array)
}
ZnVuIGdub21lU29ydChhcnJheTogTXV0YWJsZUxpc3Q8SW50PikgewogICAgdmFyIGkgPSAwCiAgICB3aGlsZSAoaSA8IGFycmF5LmNvdW50KCkpIHsKICAgICAgICBpZiAoaSA9PSAwIHx8IGFycmF5W2ldID49IGFycmF5W2kgLSAxXSkgewogICAgICAgICAgICBpKysKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWwgdG1wID0gYXJyYXlbaV0KICAgICAgICAgICAgYXJyYXlbaV0gPSBhcnJheVtpIC0gMV0KICAgICAgICAgICAgYXJyYXlbaSAtIDFdID0gdG1wCiAgICAgICAgICAgIGktLQogICAgICAgIH0KICAgIH0KfQoKZnVuIG1haW4oKSB7CiAgICB2YWwgYXJyYXkgPSBtdXRhYmxlTGlzdE9mKDcsIDMsIDAsIDEsIDUsIDIsIDUsIDE5LCAxMCwgNSkKCiAgICBnbm9tZVNvcnQoYXJyYXkpCgogICAgcHJpbnRsbihhcnJheSkKfQ==
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]