fork download
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)
}
Success #stdin #stdout 0.1s 39516KB
stdin
Standard input is empty
stdout
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]