fork download
  1. fun gnomeSort(array: MutableList<Int>) {
  2. var i = 0
  3. while (i < array.count()) {
  4. if (i == 0 || array[i] >= array[i - 1]) {
  5. i++
  6. } else {
  7. val tmp = array[i]
  8. array[i] = array[i - 1]
  9. array[i - 1] = tmp
  10. i--
  11. }
  12. }
  13. }
  14.  
  15. fun main() {
  16. val array = mutableListOf(7, 3, 0, 1, 5, 2, 5, 19, 10, 5)
  17.  
  18. gnomeSort(array)
  19.  
  20. println(array)
  21. }
Success #stdin #stdout 0.09s 39508KB
stdin
Standard input is empty
stdout
[0, 1, 2, 3, 5, 5, 5, 7, 10, 19]