Last active
October 16, 2017 17:36
-
-
Save adames/a1fbf4bc34550fa42e0567532e4b2f2b to your computer and use it in GitHub Desktop.
Very concise quicksort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My blog post breaking this algorithm down: https://medium.com/@adames/quicksort-partition-and-method-methods-f904417af5ee