FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-visualizer/src/algorithms/quickSort.ts at master · dev-grid/algorithm-visualizer · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
dev-grid
/
algorithm-visualizer
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-visualizer
/
src
/
algorithms
/
quickSort.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (54 loc) · 1.49 KB
Breadcrumbs
algorithm-visualizer
/
src
/
algorithms
/
quickSort.ts
Copy path
File metadata and controls
58 lines (54 loc) · 1.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
49
50
51
52
53
54
55
56
57
58
import
{
AnimationArrayType
}
from
"@/lib/types"
;
function
partition
(
array
:
number
[
]
,
begin
:
number
,
finish
:
number
,
animations
:
AnimationArrayType
)
{
let
i
=
begin
;
let
j
=
finish
+
1
;
const
condition
=
true
;
const
pivot
=
array
[
begin
]
;
while
(
condition
)
{
while
(
array
[
++
i
]
<=
pivot
)
{
if
(
i
===
finish
)
break
;
animations
.
push
(
[
[
i
]
,
false
]
)
;
}
while
(
array
[
--
j
]
>=
pivot
)
{
if
(
j
===
begin
)
break
;
animations
.
push
(
[
[
j
]
,
false
]
)
;
}
if
(
j
<=
i
)
break
;
animations
.
push
(
[
[
i
,
array
[
j
]
]
,
true
]
)
;
animations
.
push
(
[
[
j
,
array
[
i
]
]
,
true
]
)
;
[
array
[
i
]
,
array
[
j
]
]
=
[
array
[
j
]
,
array
[
i
]
]
;
}
animations
.
push
(
[
[
begin
,
array
[
j
]
]
,
true
]
)
;
animations
.
push
(
[
[
j
,
array
[
begin
]
]
,
true
]
)
;
[
array
[
begin
]
,
array
[
j
]
]
=
[
array
[
j
]
,
array
[
begin
]
]
;
return
j
;
}
function
runQuickort
(
array
:
number
[
]
,
begin
:
number
,
finish
:
number
,
animations
:
AnimationArrayType
)
{
if
(
begin
<
finish
)
{
const
part
=
partition
(
array
,
begin
,
finish
,
animations
)
;
runQuickort
(
array
,
begin
,
part
-
1
,
animations
)
;
runQuickort
(
array
,
part
+
1
,
finish
,
animations
)
;
}
}
export
function
generateQuickSortAnimationArray
(
isSorting
:
boolean
,
array
:
number
[
]
,
runAnimation
:
(
animations
:
AnimationArrayType
)
=>
void
)
{
if
(
isSorting
)
return
;
if
(
array
.
length
<=
1
)
return
array
;
const
animations
:
AnimationArrayType
=
[
]
;
const
auxiliaryArray
=
array
.
slice
(
)
;
runQuickort
(
auxiliaryArray
,
0
,
array
.
length
-
1
,
animations
)
;
runAnimation
(
animations
)
;
}
Back
|
FazBrowse Home
|
New Git URL