FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/basic/sorting/ShellSort/ShellSort.js at main · ManolinCoder/leetcode · GitHub
ManolinCoder
leetcode
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
basic
/
sorting
/
ShellSort
/
ShellSort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (19 loc) · 527 Bytes
Breadcrumbs
leetcode
/
basic
/
sorting
/
ShellSort
/
ShellSort.js
Copy path
File metadata and controls
21 lines (19 loc) · 527 Bytes
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
function
shellSort
(
arr
)
{
var
len
=
arr
.
length
;
var
gapSize
=
Math
.
floor
(
len
/
2
)
;
while
(
gapSize
>
0
)
{
for
(
var
i
=
gapSize
;
i
<
len
;
i
++
)
{
var
temp
=
arr
[
i
]
;
var
j
=
i
;
while
(
j
>=
gapSize
&&
arr
[
j
-
gapSize
]
>
temp
)
{
arr
[
j
]
=
arr
[
j
-
gapSize
]
;
j
-=
gapSize
;
}
arr
[
j
]
=
temp
;
}
gapSize
=
Math
.
floor
(
gapSize
/
2
)
;
}
return
arr
;
}
let
arr
=
[
6
,
3
,
2
,
1
,
5
]
;
console
.
log
(
shellSort
(
arr
)
)
Back
|
FazBrowse Home
|
New Git URL