Skip to content

Instantly share code, notes, and snippets.

@cpkenn09y
Created September 22, 2013 01:02
Show Gist options
  • Save cpkenn09y/6655660 to your computer and use it in GitHub Desktop.
Save cpkenn09y/6655660 to your computer and use it in GitHub Desktop.
Bubble Sorts!! Able to see it unfold in the terminal :)
def bubble(array)
incrementer = 0
until incrementer == array.length - 1
array.each_with_index do |e,i|
p array
unless array[i+1] == nil
if array[i] > array[i+1]
array[i] = array[i+1]
array[i+1] = e
end
end
end
p incrementer += 1
end
end
bubble([9,4,3,7,1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment