const swap = function(array,index1,index2) {
[array[index1],array[index2]] = [array[index2],array[index1]]
}
const quick = function(array,left,right) {
let index;
if(array.length > 1) {
index = partition(array,left,right);
if(left < index - 1){
quick(array,left,index - 1)
}
if(index < right) {
quick(array,index,right)
}
}
}
const partition = function(array,left,right) {
const pivot = array[Math.floor((right + left)/2)]
let [i,j] = [left,right];
while(i<=j){
while(array[i] < pivot){
i++
}
while(array[j] > pivot){
j--
}
if(i<=j){
swap(array,i,j);
i++;
j--
}
}
return i;
}
const buildHeap = function(array) {
let heapSize = array.length;
for (let i = Math.floor(array.lengt
ES6排序算法
最新推荐文章于 2024-03-12 09:32:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)