-
-
Save anonymous/bf9a591c8f1dc5eb984d 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 bubbleSort(input) | |
len = input.length | |
not_sorted = true | |
while not_sorted | |
i = 0 | |
not_sorted = false | |
while i < len-1 | |
first = input[i] | |
second = input[i+1] | |
if first > second | |
first, second = second, first # This DOES NOT work, why? | |
not_sorted = true | |
end | |
i += 1 | |
end | |
len -= 1 | |
end | |
input | |
end | |
def bubbleSort(input) | |
len = input.length | |
not_sorted = true | |
while not_sorted | |
i = 0 | |
not_sorted = false | |
while i < len-1 | |
if input[i] > input[i+1] | |
input[i], input[i+1] = input[i+1], input[i] # This DOES work | |
not_sorted = true | |
end | |
i += 1 | |
end | |
len -= 1 | |
end | |
input | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment