Skip to content

Instantly share code, notes, and snippets.

@lailsonbm
Created November 3, 2010 21:37
Show Gist options
  • Save lailsonbm/661764 to your computer and use it in GitHub Desktop.
Save lailsonbm/661764 to your computer and use it in GitHub Desktop.
Bubble sort implementation in Ruby
def bubble_sort(list)
swapped = true
while swapped
swapped = false
(list.size - 1).times do |i|
if list[i] > list[i+1]
list[i], list[i+1] = list[i+1], list[i]
swapped = true
end
end
end
list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment