2
                                                                                                                                                                                                                   
  1 function quickSort(arr){
  2     //取基准
  3     var pointIndex=Math.floor(arr.length/2);
  4     //数组去除基准元素,并取出其值
  5     var pointValue=arr.splice(pointIndex,1)[0];
  6     var left=[],
  7         right=[];
  8     for(var i=0,length=arr.length;i<length;i++){
  9         arr[i]<pointValue?left.push(arr[i]):right.push(arr[i]);
 10     }
 11     return quickSort(left).concat([pointValue],quickSort(right));
 12 }

基准
遍历分出两个数组
递归


_ipo
179 声望15 粉丝

bug