Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created November 4, 2015 19:57
Show Gist options
  • Save jordanhudgens/7fb33861aa72122d3dd6 to your computer and use it in GitHub Desktop.
Save jordanhudgens/7fb33861aa72122d3dd6 to your computer and use it in GitHub Desktop.
def bubble_sort(array)
n = array.length
loop do
swapped = false
(n-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