Skip to content

Instantly share code, notes, and snippets.

@MBM1607
Created February 25, 2021 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MBM1607/0ff37d842dd8013a49e74a7ed369c9f5 to your computer and use it in GitHub Desktop.
Save MBM1607/0ff37d842dd8013a49e74a7ed369c9f5 to your computer and use it in GitHub Desktop.
bubble sort with ruby
def bubble_sort(array)
sorted = false
until sorted do
sorted = true
array.each_with_index do |_, i|
if i + 1 != array.length && array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
sorted = false
end
end
end
return array
end
p bubble_sort([4,3,78,2,0,2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment