“My quick sort algorithm is not working”
Your code so far
function quickSort(array,start=0,end=array.length-1){
if(start<end){
pIndex=partition(array,start,end);
quickSort(array,start,pIndex-1);
quickSort(array,pIndex+1,end);}
// change code above this line
return array;
}
function partition(array,start=0,end=array.length-1){
let pIndex=start;
let pivot=array[end];
for(let i=start;i<end;i++){
if(array[i]<=pivot){
[array[i],array[pIndex]]=[array[pIndex],array[i]];
pIndex+=1
}
}
[array[pIndex],array[end]]=[array[end],array[pIndex]];
return pIndex;
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:80.0) Gecko/20100101 Firefox/80.0
.
Challenge: Implement Quick Sort
Link to the challenge: