function quickSort(arr = [3, 7, 20, 1, 10, 6, 15, 5, 12]) {
if (arr.length <= 1) return arr
const leftArr,rightArr = [],
let current = null
current = arr.splice(0, 1)
for (let i = 0; i < arr.length; i++) {
arr[i] < current ? leftArr.push(arr[i]) : rightArr.push(arr[i])
}
return quickSort(leftArr).concat(current, quickSort(rightArr))
}
原文地址:https://www.cnblogs.com/rrrjc/p/11258632.html
时间: 2024-10-13 09:58:47