Skip to content

Instantly share code, notes, and snippets.

@adames
Last active October 16, 2017 17:36
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 adames/a1fbf4bc34550fa42e0567532e4b2f2b to your computer and use it in GitHub Desktop.
Save adames/a1fbf4bc34550fa42e0567532e4b2f2b to your computer and use it in GitHub Desktop.
Very concise quicksort
class Array
def quicksort
return [] if empty?
pivot = delete_at(rand(size))
left, right = partition(&pivot.method(:>))
return *left.quicksort, pivot, *right.quicksort
end
end
@adames
Copy link
Author

adames commented Oct 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment