Skip to content

Instantly share code, notes, and snippets.

@adames
Created October 13, 2017 20:38
Show Gist options
  • Save adames/6ca4e0f01440a8d048fab204f2ec81fa to your computer and use it in GitHub Desktop.
Save adames/6ca4e0f01440a8d048fab204f2ec81fa to your computer and use it in GitHub Desktop.
Splitting an array between an integer for a quicksort method
def partition(array, pivot)
return [], [] if array.empty?
j = 0
for i in 0...array.length
if array[i] <= pivot
array[j], array[i] = array[i], array[j]
j += 1
end
end
return array[0...j], array[j..-1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment