<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
//递归 1.阶乘 2.数组扁平化 3.深克隆 4.快速排序 5.杨辉三角 6.输入1到100
const x = [1]
const y = [2]
const z = [3]
console.log(x.concat(y,z))
function quickSort(arr){
//终止条件
if(arr.length <= 1){
return arr
}
const pivot = arr[0]
var bigger = []
var smaller = []
for(let i = 1; i < arr.length ;i ++){
if(arr[i] >= pivot){
bigger.push(arr[i])
}else{
smaller.push(arr[i])
}
}
return quickSort(smaller).concat(pivot,quickSort(bigger))
}
var arr = [56,3234,23,64,3,45,12,456,88,99,32]
console.log(quickSort(arr))
</script>
</body>
</html>
js的快速排序
最新推荐文章于 2024-08-03 21:38:43 发布