Created
March 11, 2017 21:45
-
-
Save a-eid/24d2992b4d585992896b9f25dfb8e371 to your computer and use it in GitHub Desktop.
bubble sort attempt ruby
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_sort(a) | |
i = 0 | |
len = a.size - 1 | |
while len >= i | |
j = 0 | |
while len > j | |
if a[j] > a[j+1] | |
tmp = a[j] | |
a[j] = a[j + 1] | |
a[j + 1] = tmp | |
end | |
j += 1 | |
end | |
p "len #{len}" | |
p "i #{i}" | |
len -= 1 | |
i += 1 | |
end | |
a | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment