public
Last active

buddle_sort

  • Download Gist
sort.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12
def bubble_sort(list)
(list.length() - 1).downto(0).each { |bubble_to_index|
(0..(bubble_to_index - 1)).each { |bubbling_index|
if list[bubbling_index] > list[bubbling_index + 1]
tmp = list[bubbling_index]
list[bubbling_index] = list[bubbling_index + 1]
list[bubbling_index + 1] = tmp
end
}
}
list
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.