Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Created November 28, 2012 12:44
Show Gist options
  • Save vderyagin/4161004 to your computer and use it in GitHub Desktop.
Save vderyagin/4161004 to your computer and use it in GitHub Desktop.
quick sort implementation in ruby
def quick_sort(list)
return list.dup unless list.size > 1
x = list.sample
h = list.group_by { |item| item <=> x }
h.default = []
less, equal, more = h[-1], h[0], h[1]
quick_sort(less) + equal + quick_sort(more)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment