Skip to content

Instantly share code, notes, and snippets.

@kelvin8773 kelvin8773/quick-sort.rb

Last active Jul 24, 2019
Embed
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
end
[left, pivot , right]
end
return array if array.size <= 1
left, pivot , right = partition(array)
res = quicksort(left) + [pivot] + quicksort(right)
return res
end
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.