文章目录
function fastSort(arr, left = 0, right = arr.length - 1) {
if(left>=right){
return;
}
let i = left;
let j = right;
while (i < j) {
while (true && i<j) {
if (arr[j] < arr[i]) {
let temp = arr[j];
arr[j] = arr[i];
arr[i++] = temp;
break;
}else{
j--;
}
}
while(true && i<j){
if(arr[j]<arr[i]){
let temp = arr[j];
arr[j--] = arr[i];
arr[i] = temp;
break;
}else{
i++;
}
}
}
fastSort(arr, left, i-1);
fastSort(arr, i+1, right);
}
let arr = [1, 2, -1, -10, 77,100,0,700,0];
fastSort(arr);
console.log(arr);