Created
September 22, 2013 01:02
-
-
Save cpkenn09y/6655660 to your computer and use it in GitHub Desktop.
Bubble Sorts!! Able to see it unfold in the terminal :)
This file contains hidden or 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(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