# 快速排序
function quick (array) {
if (array.length==0) return [];
let pivot = array[0];
let lesser = [];
let greater = [];
for (let i=1;i<array.length;i++) {
if(array[i]<pivot){
lesser.push(array[i])
}else {
greater.push(array[i])
}
}
return quick(lesser).concat(pivot,quick(greater))
}
console.log(quick([9,3,25,4,1,47,6,8,5,10,25]))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
← 为什么你的对象时快时慢呢 选择排序 →