fun cocktailShakerSort(array: MutableList<Int>) {
for (i in 0 until array.count() / 2 + 1) {
for (j in i until array.count() - i - 1) {
if (array[j] > array[j + 1]) {
val tmp = array[j]
array[j] = array[j + 1]
array[j + 1] = tmp
}
}
for (j in array.count() - 1 - i downTo i + 1) {
if (array[j] < array[j - 1]) {
val tmp = array[j]
array[j] = array[j - 1]
array[j - 1] = tmp
}
}
}
}
fun main() {
val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
cocktailShakerSort(array)
println(array)
}
ZnVuIGNvY2t0YWlsU2hha2VyU29ydChhcnJheTogTXV0YWJsZUxpc3Q8SW50PikgewogICAgZm9yIChpIGluIDAgdW50aWwgYXJyYXkuY291bnQoKSAvIDIgKyAxKSB7CiAgICAgICAgZm9yIChqIGluIGkgdW50aWwgYXJyYXkuY291bnQoKSAtIGkgLSAxKSB7CiAgICAgICAgICAgIGlmIChhcnJheVtqXSA+IGFycmF5W2ogKyAxXSkgewogICAgICAgICAgICAgICAgdmFsIHRtcCA9IGFycmF5W2pdCiAgICAgICAgICAgICAgICBhcnJheVtqXSA9IGFycmF5W2ogKyAxXQogICAgICAgICAgICAgICAgYXJyYXlbaiArIDFdID0gdG1wCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgZm9yIChqIGluIGFycmF5LmNvdW50KCkgLSAxIC0gaSBkb3duVG8gaSArIDEpIHsKICAgICAgICAgICAgaWYgKGFycmF5W2pdIDwgYXJyYXlbaiAtIDFdKSB7CiAgICAgICAgICAgICAgICB2YWwgdG1wID0gYXJyYXlbal0KICAgICAgICAgICAgICAgIGFycmF5W2pdID0gYXJyYXlbaiAtIDFdCiAgICAgICAgICAgICAgICBhcnJheVtqIC0gMV0gPSB0bXAKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKCmZ1biBtYWluKCkgewogICAgdmFsIGFycmF5ID0gbXV0YWJsZUxpc3RPZig3LCAzLCAwLCAxLCA1LCAyLCA1LCAxOSwgMTAsIDUpCiAgICAKICAgIGNvY2t0YWlsU2hha2VyU29ydChhcnJheSkKICAgICAgICAKICAgIHByaW50bG4oYXJyYXkpCn0=