Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Last active April 30, 2021 11:43
Show Gist options
  • Select an option

  • Save syedjafer/30d0cfd2bebda89ff346210aefe2a665 to your computer and use it in GitHub Desktop.

Select an option

Save syedjafer/30d0cfd2bebda89ff346210aefe2a665 to your computer and use it in GitHub Desktop.
function partition(array, low, high){
var pivot = array[high];
var partition_index = low;
var temp;
for (var itr=low; itr<high; itr++){
if (array[itr]<pivot){
temp = array[itr];
array[itr] = array[partition_index];
array[partition_index] = temp;
partition_index += 1
}
console.log(array);
}
temp = array[high];
array[high] = array[partition_index];
array[partition_index] = temp;
console.log(array);
}
var array = [3, 8, 6, 2, 4, 7, 8, 5];
partition(array, 0, 7);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment