图解
代码
javascript
let quickSort = function(arr, left, right){
if(left > right){
return;
}
let key = arr[left];
let i = left;
let j = right;
while(i < j){
while(i<j && arr[j] >= key){
j--;
}
while(i<j && arr[i] <= key){
i++;
}
if(i<j){
let tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
// 在重合点 将基准值交换
arr[left] = arr[i];
arr[i] = key;
quickSort(arr, left, i-1);
quickSort(arr, i+1, right);
}