Skip to content

Instantly share code, notes, and snippets.

@aspencer8111
Created March 13, 2017 14:46
Show Gist options
  • Save aspencer8111/415ce314b83c0f20345259aa6c375457 to your computer and use it in GitHub Desktop.
Save aspencer8111/415ce314b83c0f20345259aa6c375457 to your computer and use it in GitHub Desktop.
A simple bubble sort algorithm in ruby
def bubble_sort(array)
loop do
swapped = false
(array.length-1).times do |i|
if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
swapped = true
end
end
break if not swapped
end
array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment