Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick Sort advance in Ruby
def advanced_quicksort(array)
def helper(array, start=0, last=array.size-1)
return array if last-start < 1
pivot = array[last]
middle = start - 1
for i in start..last
array[i] <= pivot ? (middle += 1; array[i], array[middle] = array[middle], array[i] ) : array[i]
end
# puts array.join(" ")
helper(array, start, middle-1)
helper(array, middle+1, last)
end
result = array.dup
helper(result)
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.