Skip to content

Instantly share code, notes, and snippets.

@kelvin8773 kelvin8773/quick-sort.rb

Last active Jul 24, 2019
What would you like to do?
quick sorting method in Ruby
def quicksort(array)
def partition(array)
pivot,left, right =array[0], [], []
array[1..-1].each do |x|
x > pivot ? right << x : left << x
[left, pivot , right]
return array if array.size <= 1
left, pivot , right = partition(array)
res = quicksort(left) + [pivot] + quicksort(right)
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.