-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort.html
More file actions
48 lines (45 loc) · 1.32 KB
/
Copy pathquickSort.html
File metadata and controls
48 lines (45 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!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>
</head>
<body>
<script>
const quickSort=(list,left,right)=>{
const wrap = (list,pointer1,pointer2)=>{
let temp = list[pointer1]
list[pointer1] = list[pointer2]
list[pointer2] = temp
}
const patition = (list,left,right)=>{
if(left>=right){
return
}
let pival = list[left]
let pointer1 = left
let pointer2 = right+1
while(true){
while(list[++pointer1] < pival) { if(pointer1 == right) {break} }
while(list[--pointer2] > pival) { if(pointer2 == left) {break} }
if(pointer1>=pointer2) break
wrap(list,pointer1,pointer2)
}
wrap(list,left,pointer2)
return pointer2
}
if(right <= left){
return
}
let position = patition(list,left,right)
quickSort(list,left,position-1)
quickSort(list,position+1,right)
}
res = [9,8,7,6,5,4,3,2,1]
quickSort(res,0,res.length-1)
console.log(res)
</script>
</body>
</html>