【数组快排】有空再补描述。
function quickSort(array) {
function sort(arr,left = 0,right = arr.length - 1) {
if (left >= right) { return arr;
}
let i = left, j = right, baseVindex = j;
const len = arr.length, baseV = arr[baseVindex];
while (i baseV) {
// let temp = arr[i];
// arr[i] = baseV;
// arr[baseVindex] = arr[i];
// baseVindex = i;
[arr[i], arr[baseVindex], baseVindex] = [arr[baseVindex], arr[i], i];
break;
}
i ++;
}
while (j>=0 && j>i) {
if (arr[j] < baseV) {
[arr[j], arr[baseVindex], baseVindex] = [arr[baseVindex], arr[j], j];
break;
}
j --;
}
}
// arguments.callee(arr,left,baseVindex-1);
// arguments.callee(arr,baseVindex+1,right);
sort(arr,left,baseVindex-1);
sort(arr,baseVindex+1,right);
}
let arr = array.concat();
sort(arr)
return arr;
}