function qucikSort (arr) {
if (arr.length <= 1) {
return arr
}
var num = Math.floor(arr.length / 2)
var numVal = arr.splice(num, 1)
var left = []
var right = []
for (var i = 0; i < arr.length; i++) {
if (arr[i] < numVal) {
left.push(arr[i])
} else if (arr[i] > numVal) {
right.push(arr[i])
}
}
return qucikSort(left).concat(numVal, qucikSort(right))
}
网友评论