Created
April 10, 2017 16:36
-
-
Save Shurlow/8d815dc63b30b0eca27d1fd29b501574 to your computer and use it in GitHub Desktop.
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
function swap(arr, idx1, idx2) { | |
let temp = arr[idx1]; | |
arr[idx1] = arr[idx2]; | |
arr[idx2] = temp; | |
} | |
function partition(arr, left, right) { | |
let pivotValue = arr[left]; | |
let partitionIndex = left; | |
for (let i = left + 1; i <= right; i++) { | |
if (arr[i] < pivotValue) { | |
partitionIndex++; | |
swap(arr, i, partitionIndex); | |
} | |
} | |
swap(arr, left, partitionIndex); | |
return partitionIndex; | |
} | |
function unknownAlgorithm(arr, left=0, right=arr.length - 1) { | |
if (left < right) { | |
let partitionIndex = partition(arr, left, right); | |
unknownAlgorithm(arr, left, partitionIndex - 1); | |
unknownAlgorithm(arr, partitionIndex + 1, right); | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment