js实现快排
const fast_sort = (nums) => {
if (nums.length === 0) {
return []
} else {
let first = nums[0]
let left = []
let right = []
nums.forEach((item, index) => {
if (index > 0) {
if (item >= first) {
right.push(item)
} else {
left.push(item)
}
}
})
return fast_sort(left).concat([first]).concat(fast_sort(right))
}
}
nums = [12,
js实现快排最先出现在Python成神之路。
共有 0 条评论