Skip to content

Instantly share code, notes, and snippets.

@barce
Created December 29, 2009 06:14
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 barce/265181 to your computer and use it in GitHub Desktop.
Save barce/265181 to your computer and use it in GitHub Desktop.
def quicksort(a)
return a if a.size <= 1
p = a[0] # pivot element
quicksort(a.select {|i| i < p }) + a.select {|i| i == p} + quicksort(a.select {|i| i > p })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment