标签:cat 快速排序 val pre UNC 去重 col dex floor
var arr1 = [10,9,2,5,7,34,65,48,90,103]; var newArr=[]; /* for(var i=0;i<arr.length;i++){ newArr.indexOf(arr[i])<0 && (newArr.push(arr[i])); } */ // newArr = Array.from(new Set(arr)); // 快速排序 function quikSort(arr){ if(arr.length<=1)return arr; var midIndex = Math.floor(arr.length/2); var midVal = arr.splice(midIndex,1)[0]; var leftArr = []; var rightArr = []; for (var val of arr){ if(val<midVal){leftArr.push(val)}else{rightArr.push(val)} } /* for(var k=0;k<arr.length;k++){ if( arr[k]<midVal ){ leftArr.push(arr[k]) }else{ rightArr.push(arr[k]) } } */ return quikSort(leftArr).concat(midVal,quikSort(rightArr)); } console.log( quikSort(arr1) );
标签:cat 快速排序 val pre UNC 去重 col dex floor
原文地址:https://www.cnblogs.com/smile-fanyin/p/10793537.html