Skip to content

Instantly share code, notes, and snippets.

@kelvin8773
Created July 24, 2019 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelvin8773/b5097b9afc12cf01a10b88f03fe53d12 to your computer and use it in GitHub Desktop.
Save kelvin8773/b5097b9afc12cf01a10b88f03fe53d12 to your computer and use it in GitHub Desktop.
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