MCPcopy Create free account
hub / github.com/course-dasheng/fe-algorithm / quickSort

Function quickSort

sort/sort.js:32–47  ·  view source on GitHub ↗
(arr)

Source from the content-addressed store, hash-verified

30// O(n * lgn)
31
32function quickSort(arr){
33 if(arr.length<2){
34 return arr
35 }
36 let flag = arr[0]
37 let left = []
38 let right = []
39 for(let i=1;i<arr.length;i++){
40 if(arr[i]>flag){
41 right.push(arr[i])
42 }else{
43 left.push(arr[i])
44 }
45 }
46 return quickSort(left).concat(flag,quickSort(right))
47}
48// console.log('快速排序',quickSort(arrary))
49
50// 原地快排

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected