Created
October 13, 2017 20:38
-
-
Save adames/6ca4e0f01440a8d048fab204f2ec81fa to your computer and use it in GitHub Desktop.
Splitting an array between an integer for a quicksort method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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