<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
const arr=[12,34,3,5,8,2,9,6,89,22,8];
function quickSort(arr){
if(arr.length<=1){
return arr;
}
const currentIndex=Math.floor(arr.length/2);
const center=arr.splice(currentIndex,1)[0];
const leftArr=[];
const rightArr=[];
for(let i=0;i<arr.length;i++){
if(arr[i]<center){
leftArr.push(arr[i]);
}else{
rightArr.push(arr[i])
}
}
return quickSort(leftArr).concat(center,quickSort(rightArr));
}
const result=quickSort(arr);
console.log(result,99966)
</script>
</head>
<body>
</body>
</html>
08-04
445
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-16
09-19
667
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交