fork download
  1. def bubble_sort(array)
  2. sorted = false
  3. while sorted
  4. array.each do |i|
  5. if array[i] < array[i+1]
  6. array[i], array[i+1] = array[i+1], array[i]
  7. end
  8. sorted = true
  9. end
  10. end
  11. array
  12. end
  13.  
  14. p bubble_sort([6, 2, 7, 1, 8, 5])
Success #stdin #stdout 0.05s 9696KB
stdin
Standard input is empty
stdout
[6, 2, 7, 1, 8, 5]