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

Function quick1

sort/sort.js:59–79  ·  view source on GitHub ↗
(arr,start,end)

Source from the content-addressed store, hash-verified

57
58空间复杂度变成了O1
59function quick1(arr,start,end){
60 // 双指针
61 let init = start
62 let flag = arr[init]
63 start++
64 while(start<=end){
65 while(arr[end]>flag){
66 end--
67 }
68 while(arr[start]<flag){
69 start++
70 }
71 if(start<end){
72 [arr[start],arr[end]] = [arr[end],arr[start]]
73 start++
74 end--
75 }
76 }
77 [arr[init],arr[start-1]] = [arr[start-1],arr[init]]
78 return start
79}
80function quickSort1(arr,start,end){
81 if(start<end){
82 let index = quick1(arr,start,end) //标志位的值

Callers 1

quickSort1Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected