Guest User

Untitled

a guest
Dec 12th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.32 KB | None | 0 0
  1. def bubbleSort(array)
  2.     for i in array
  3.         for j in array.reverse
  4.             if array[j] < array[j - 1]
  5.                 t = array[j]
  6.                 array[j] = array[j - 1]
  7.                 array[j - 1] = t
  8.             end
  9.         end
  10.     end
  11.     return array
  12. end
  13.    
  14. array = [9, 1, 8, 2, 7, 3, 6, 4, 5]
  15. puts '[' + array.join(', ') + ']'
  16. puts '[' + bubbleSort(array).join(', ') + ']'
Advertisement
Add Comment
Please, Sign In to add comment