FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/src/test/java/sort/basic/ShellSort.java at master · verifyCode/algorithms · GitHub
verifyCode
algorithms
Repository navigation
Code
Issues
Pull requests
2
(2)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
src
/
test
/
java
/
sort
/
basic
/
ShellSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (36 loc) · 1000 Bytes
Breadcrumbs
algorithms
/
src
/
test
/
java
/
sort
/
basic
/
ShellSort.java
Copy path
File metadata and controls
40 lines (36 loc) · 1000 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package
sort
.
basic
;
import
com
.
sort
.
SortTestHelper
;
import
java
.
util
.
Arrays
;
/**
* @author xjn
* @since 2020-05-07
*/
public
class
ShellSort
{
public
static
void
sort
(
int
[]
array
) {
int
h
=
1
;
while
(
h
<
array
.
length
/
3
) {
h
=
3
*
h
+
1
;
}
while
(
h
>=
1
) {
for
(
int
i
=
h
;
i
<
array
.
length
;
i
++) {
int
element
=
array
[
i
];
int
j
;
for
(
j
=
i
;
j
>=
h
;
j
--) {
if
(
array
[
j
-
1
] >
element
) {
array
[
j
] =
array
[
j
-
1
];
}
else
{
break
;
}
}
array
[
j
] =
element
;
}
h
/=
3
;
}
}
public
static
void
main
(
String
[]
args
) {
int
[]
ints
=
SortTestHelper
.
generateRandomArray
(
10
,
1
,
10
);
System
.
out
.
println
(
Arrays
.
toString
(
ints
));
sort
(
ints
);
System
.
out
.
println
(
Arrays
.
toString
(
ints
));
}
}
Back
|
FazBrowse Home
|
New Git URL