Created
November 3, 2010 21:37
-
-
Save lailsonbm/661764 to your computer and use it in GitHub Desktop.
Bubble sort implementation in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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