fork download
  1. fun cocktailShakerSort(array: MutableList<Int>) {
  2. for (i in 0 until array.count() / 2 + 1) {
  3. for (j in i until array.count() - i - 1) {
  4. if (array[j] > array[j + 1]) {
  5. val tmp = array[j]
  6. array[j] = array[j + 1]
  7. array[j + 1] = tmp
  8. }
  9. }
  10.  
  11. for (j in array.count() - 1 - i downTo i + 1) {
  12. if (array[j] < array[j - 1]) {
  13. val tmp = array[j]
  14. array[j] = array[j - 1]
  15. array[j - 1] = tmp
  16. }
  17. }
  18. }
  19. }
  20.  
  21.  
  22. fun main() {
  23. val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
  24.  
  25. cocktailShakerSort(array)
  26.  
  27. println(array)
  28. }
Success #stdin #stdout 0.1s 39516KB
stdin
Standard input is empty
stdout
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]