FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/basic/sorting/ShellSort/ShellSort.java 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.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (21 loc) · 651 Bytes
Breadcrumbs
leetcode
/
basic
/
sorting
/
ShellSort
/
ShellSort.java
Copy path
File metadata and controls
25 lines (21 loc) · 651 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
22
23
24
25
import
java
.
util
.
Arrays
;
public
class
ShellSort
{
private
static
int
[]
shellSort
(
int
[]
arr
) {
int
n
=
arr
.
length
;
for
(
int
gap
=
n
/
2
;
gap
>
0
;
gap
/=
2
) {
for
(
int
i
=
gap
;
i
<
n
;
i
++) {
int
key
=
arr
[
i
];
int
j
=
i
;
while
(
j
>=
gap
&&
arr
[
j
-
gap
] >
key
) {
arr
[
j
] =
arr
[
j
-
gap
];
j
-=
gap
;
}
arr
[
j
] =
key
;
}
}
return
arr
;
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
Arrays
.
toString
(
shellSort
(
new
int
[]{
1
,
2
,
7
,
9
,
5
,
8
})));
}
}
Back
|
FazBrowse Home
|
New Git URL