我正在尝试实现快速排序的内存密集型实现,第一种排序the first chunk of code described here
function quickSort(arr){
var less = [];
var more = [];
var equals = [];
//Find a rough median
if (arr.length > 1){
var pivot = arr[Math.floor((arr.length/2))];
for (var i = 0; i < arr.length; i++){
if (arr[i] < pivot){
less.push(arr[i]);
}
else if (arr[i] == pivot){
equals.push(arr[i]);
}
else if (arr[i] > pivot){
more.push(arr[i]);
}
}
quickSort(less);quickSort(more);
return less.concat(equals,more);
}
}
我传入了无序的浮动列表= [3, 4, 54, 6, 6, 4, 3, 2, 2]
它输出这个[3, 4, 4, 3, 2, 2, 6, 6, 54]
显然不考虑几个案例。发生了什么事?