fork download
  1. def bubble_sort(array)
  2. for i in 1..array.length-1
  3. array[i], array[i-1] = array[i-1], array[i] if array[i] < array[i-1]
  4. end
  5. array
  6. end
  7.  
  8.  
  9. p bubble_sort([2, 1, 6, 3, 7, 4])
Success #stdin #stdout 0.06s 9608KB
stdin
Standard input is empty
stdout
[1, 2, 3, 6, 4, 7]