Created
November 4, 2015 19:57
-
-
Save jordanhudgens/7fb33861aa72122d3dd6 to your computer and use it in GitHub Desktop.
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(array) | |
n = array.length | |
loop do | |
swapped = false | |
(n-1).times do |i| | |
if array[i] > array[i+1] | |
array[i], array[i+1] = array[i+1], array[i] | |
swapped = true | |
end | |
end | |
break if not swapped | |
end | |
array | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment