FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AlgorithmVisualizer/algorithm/sorting/bucket/basic/code.js at master · AnnPin/AlgorithmVisualizer · GitHub
AnnPin
/
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
/
bucket
/
basic
/
code.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (32 loc) · 1.03 KB
Breadcrumbs
AlgorithmVisualizer
/
algorithm
/
sorting
/
bucket
/
basic
/
code.js
Copy path
File metadata and controls
34 lines (32 loc) · 1.03 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
//place numbers into appropriate buckets
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
var
bucketPos
=
Math
.
floor
(
numBuckets
*
(
array
[
i
]
/
maxValue
)
)
;
buckets
[
bucketPos
]
.
push
(
array
[
i
]
)
;
bucketsCount
[
bucketPos
]
++
;
tracer
.
_select
(
0
,
i
)
.
_wait
(
)
;
tracer
.
_notify
(
1
,
bucketPos
,
D
[
1
]
[
bucketPos
]
)
.
_wait
(
)
;
tracer
.
_deselect
(
0
,
i
)
;
tracer
.
_denotify
(
1
,
bucketPos
,
D
[
1
]
[
bucketPos
]
)
;
}
var
sortLocation
=
0
;
for
(
let
k
=
0
;
k
<
buckets
.
length
;
k
++
)
{
//do insertion sort
for
(
let
i
=
1
;
i
<
buckets
[
k
]
.
length
;
i
++
)
{
var
key
=
buckets
[
k
]
[
i
]
;
var
j
;
for
(
j
=
i
-
1
;
(
j
>=
0
)
&&
(
buckets
[
k
]
[
j
]
>
key
)
;
j
--
)
{
buckets
[
k
]
[
j
+
1
]
=
buckets
[
k
]
[
j
]
;
}
buckets
[
k
]
[
j
+
1
]
=
key
;
}
//place ordered buckets into sorted array
for
(
let
i
=
0
;
i
<
buckets
[
k
]
.
length
;
i
++
)
{
sortedArray
[
sortLocation
]
=
buckets
[
k
]
[
i
]
;
bucketsCount
[
k
]
--
;
tracer
.
_notify
(
1
,
k
,
D
[
1
]
[
k
]
)
;
tracer
.
_notify
(
2
,
sortLocation
,
D
[
2
]
[
sortLocation
]
)
.
_wait
(
)
;
tracer
.
_denotify
(
1
,
k
,
D
[
1
]
[
k
]
)
;
tracer
.
_denotify
(
2
,
sortLocation
,
D
[
2
]
[
sortLocation
]
)
;
sortLocation
++
;
}
}
Back
|
FazBrowse Home
|
New Git URL