Skip to content

Instantly share code, notes, and snippets.

/.rb Secret

Created February 8, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bf9a591c8f1dc5eb984d to your computer and use it in GitHub Desktop.
Save anonymous/bf9a591c8f1dc5eb984d to your computer and use it in GitHub Desktop.
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