Created
May 10, 2018 12:41
-
-
Save Mez0/2eca860855666a1177f4984c312ee1e4 to your computer and use it in GitHub Desktop.
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
def quicksort(a) | |
return a unless a.count > 1 | |
pivot = a[0] | |
less = a.select {|num| num < pivot } | |
equal = a.select {|num| num == pivot } | |
greater = a.select {|num| num > pivot } | |
return quicksort(less) + equal + quicksort(greater) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment