Skip to content

Instantly share code, notes, and snippets.

@lysu
Last active December 15, 2015 18:59
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 lysu/5307902 to your computer and use it in GitHub Desktop.
Save lysu/5307902 to your computer and use it in GitHub Desktop.
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