FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaArithmetic/src/sort/ShellSort.java at master · git-jhy/JavaArithmetic · GitHub
git-jhy
JavaArithmetic
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaArithmetic
/
src
/
sort
/
ShellSort.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (35 loc) · 1017 Bytes
Breadcrumbs
JavaArithmetic
/
src
/
sort
/
ShellSort.java
Copy path
File metadata and controls
51 lines (35 loc) · 1017 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
41
42
43
44
45
46
47
48
49
50
51
package
sort
;
/**
* Created by ozc on 2018/3/26.
*
* @author ozc
* @version 1.0
*/
public
class
ShellSort
{
public
static
void
main
(
String
[]
args
) {
int
[]
arrays
= {
6
,
4321
,
432
,
344
,
55
};
shellSort
(
arrays
);
System
.
out
.
println
(
"公众号:Java3y"
+
arrays
);
}
/**
* 希尔排序
*
* @param arrays
*/
public
static
void
shellSort
(
int
[]
arrays
) {
//增量每次都/2
for
(
int
step
=
arrays
.
length
/
2
;
step
>
0
;
step
/=
2
) {
//从增量那组开始进行插入排序,直至完毕
for
(
int
i
=
step
;
i
<
arrays
.
length
;
i
++) {
int
j
=
i
;
int
temp
=
arrays
[
j
];
// j - step 就是代表与它同组隔壁的元素
while
(
j
-
step
>=
0
&&
arrays
[
j
-
step
] >
temp
) {
arrays
[
j
] =
arrays
[
j
-
step
];
j
=
j
-
step
;
}
arrays
[
j
] =
temp
;
}
}
}
}
Back
|
FazBrowse Home
|
New Git URL