class Array def quick_sort return self if count < 2 pivot = pop parts = partition { |x| x < pivot } [*parts.first.quick_sort, pivot, *parts.last.quick_sort] end end
It's pretty straight-forward and Ruby's expressiveness really does cause the code to closely resemble the algorithm.
No comments:
Post a Comment