快速排序实现

function quickSort(arr, a, b){
var left = a,right = b;
var flagIndex = left;
if (a >= b) {
return;
}
while (left < right) {
if (arr[left] > arr[right]) {
var temp;
temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
flagIndex = flagIndex == left ? right : left;
}
if (arr[flagIndex] == arr[left]) {
right--;
} else {
left++;
}
}
quickSort(arr, a, flagIndex-1);
quickSort(arr, flagIndex+1, b);
}

你可能感兴趣的:(快速排序实现)