js---快速排序

function quiktSort(arr){
		var left = [],right = [];
		if(arr.length<1){
			return arr;
		}
		var index = Math.floor(arr.length/2);
		var point  = arr.splice(index,1);
		for(var i = 0,len = arr.length;i<len;i++){
			if(arr[i]<point){
				left.push(arr[i]);
			}else{
				right.push(arr[i]);
			}
		}
		return quiktSort(left).concat(point,quiktSort(right))
	}
	var arr = [1,45,4,85,82,2];
	console.log(quiktSort(arr))

  

posted @ 2019-08-11 16:23  Yi只猴  阅读(177)  评论(0编辑  收藏  举报