FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript/sorting/ShellSort.js at master · dcipher00/javascript · GitHub
dcipher00
/
javascript
Public
forked from
AllAlgorithms/javascript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript
/
sorting
/
ShellSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (24 loc) · 1.01 KB
Breadcrumbs
javascript
/
sorting
/
ShellSort.js
Copy path
File metadata and controls
29 lines (24 loc) · 1.01 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
/* "Shell sort or Shell's method, is an in-place comparison sort.
It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort).
The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared.
Starting with far apart elements can move some out-of-place elements into position faster than a simple nearest neighbor exchange." */
function
shellSort
(
arr
)
{
var
increment
=
arr
.
length
/
2
;
while
(
increment
>
0
)
{
for
(
i
=
increment
;
i
<
arr
.
length
;
i
++
)
{
var
j
=
i
;
var
temp
=
arr
[
i
]
;
while
(
j
>=
increment
&&
arr
[
j
-
increment
]
>
temp
)
{
arr
[
j
]
=
arr
[
j
-
increment
]
;
j
=
j
-
increment
;
}
arr
[
j
]
=
temp
;
}
if
(
increment
==
2
)
{
increment
=
1
;
}
else
{
increment
=
parseInt
(
increment
*
5
/
11
)
;
}
}
return
arr
;
}
Back
|
FazBrowse Home
|
New Git URL