Create a gist now

Instantly share code, notes, and snippets.

@lysu /sort.rb
Last active Dec 15, 2015

buddle_sort
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment