FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AlgorithmVisualizer/algorithm/sorting/comb/basic/code.js at gh-pages · rbds/AlgorithmVisualizer · GitHub
rbds
/
AlgorithmVisualizer
Public
forked from
algorithm-visualizer/algorithm-visualizer
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
AlgorithmVisualizer
/
algorithm
/
sorting
/
comb
/
basic
/
code.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (28 loc) · 1.04 KB
Breadcrumbs
AlgorithmVisualizer
/
algorithm
/
sorting
/
comb
/
basic
/
code.js
Copy path
File metadata and controls
34 lines (28 loc) · 1.04 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
logger
.
_print
(
'original array = ['
+
D
.
join
(
', '
)
+
']'
)
;
var
N
=
D
.
length
;
var
swapped
;
var
gap
=
N
;
// initialize gap size
var
shrink
=
1.3
;
// set the gap shrink factor
do
{
// update the gap value for the next comb.
gap
=
Math
.
floor
(
gap
/
shrink
)
;
if
(
gap
<
1
)
{
// minimum gap is 1
gap
=
1
;
}
swapped
=
false
;
// initialize swapped
// a single comb over the input list
for
(
var
i
=
0
;
i
+
gap
<
N
;
i
++
)
{
tracer
.
_select
(
i
)
.
_select
(
i
+
gap
)
.
_wait
(
)
;
if
(
D
[
i
]
>
D
[
i
+
gap
]
)
{
logger
.
_print
(
'swap '
+
D
[
i
]
+
' and '
+
D
[
i
+
gap
]
)
;
// log swap event
var
temp
=
D
[
i
]
;
D
[
i
]
=
D
[
i
+
gap
]
;
D
[
i
+
gap
]
=
temp
;
tracer
.
_notify
(
i
,
D
[
i
]
)
.
_notify
(
i
+
gap
,
D
[
i
+
gap
]
)
.
_wait
(
)
;
tracer
.
_denotify
(
i
)
.
_denotify
(
i
+
gap
)
;
swapped
=
true
;
// Flag swapped has happened and list is not guaranteed sorted
}
tracer
.
_deselect
(
i
)
.
_deselect
(
i
+
gap
)
;
}
// End of combing
}
while
(
gap
!=
1
||
swapped
)
Back
|
FazBrowse Home
|
New Git URL