Skip to content

Instantly share code, notes, and snippets.

@mindplace
Created February 27, 2016 00:34
Show Gist options
  • Save mindplace/b03585edd955ca2c6804 to your computer and use it in GitHub Desktop.
Save mindplace/b03585edd955ca2c6804 to your computer and use it in GitHub Desktop.
def bubble_sort(array)
sorted = false
while sorted == false
array.each_index do |i|
a = array[i]
b = array[i + 1]
if b == nil
sorted = true
break
elsif a > b
sorted = false
array[i], array[i + 1] = array[i + 1], array[i]
break
end
end
end
p array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment