Created
March 13, 2017 15:01
-
-
Save aspencer8111/0ea85304d5697cae680e96ea451c04b3 to your computer and use it in GitHub Desktop.
QuickSort added to array class
This file contains hidden or 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