fork download
  1. def bubbleSort(numbers)
  2. sorted = false
  3. until sorted
  4. sorted = true
  5. for i in 1..numbers.length-1
  6. if numbers[i-1] > numbers[i]
  7. numbers[i-1], numbers[i] = numbers[i], numbers[i-1]
  8. sorted = false
  9. end
  10. end
  11. end
  12. print numbers
  13. end
  14.  
  15. bubbleSort([7, 2, 5, 1, 9, 3])
Success #stdin #stdout 0.05s 9760KB
stdin
Standard input is empty
stdout
[1, 2, 3, 5, 7, 9]