JS快排

 1 var quicksort = function(arr){
 2     if(arr.length <= 1){
 3         return arr;
 4     }
 5     var pivotIndex = matn.floor(arr.length/2);
 6     var pivot = arr.splice(pivotIndex,1)[0];
 7     var left = [];
 8     var right = [];
 9     for (var i = 0; i < arr.length; i++){
10         if(arr[i] < pivot){
11             left.push(arr[i]);
12         }else{
13             right.push(arr[i]);
14         }
15     }
16 }
17 
18 return quicksort(left).concat([pivot], quicksort(right));

 

posted @ 2020-04-23 22:43  燕十三丶  阅读(129)  评论(0编辑  收藏  举报
AmazingCounters.com