This is an implementation of the quicksort algorithm written in Ruby. Basically, the same code you'll find on Wikibook's entry for quicksort implementations. A gem from the 'Book'.
Last active
December 25, 2015 22:19
-
-
Save O-I/7048779 to your computer and use it in GitHub Desktop.
Ruby Quicksort
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(list) | |
return list if list.length < 2 | |
pivot = list.shift | |
left, right = list.partition { |el| el < pivot } | |
quicksort(left) + [pivot] + quicksort(right) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment