Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created March 11, 2017 21:45
Show Gist options
  • Save a-eid/24d2992b4d585992896b9f25dfb8e371 to your computer and use it in GitHub Desktop.
Save a-eid/24d2992b4d585992896b9f25dfb8e371 to your computer and use it in GitHub Desktop.
bubble sort attempt ruby
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