fork download
  1. fun oddEvenSort(array: MutableList<Int>) {
  2. for (i in array.indices) {
  3. for (j in i % 2 + 1 until array.count() step 2) {
  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. }
  12.  
  13. fun main() {
  14. val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
  15.  
  16. oddEvenSort(array)
  17.  
  18. println(array)
  19. }
Success #stdin #stdout 0.1s 43656KB
stdin
Standard input is empty
stdout
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]