Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b2244b

Browse files
[A] 添加希尔排序算法代码实现
1 parent 12a76a5 commit 1b2244b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.bruis.algorithminjava.algorithm.sort;
2+
3+
/**
4+
*
5+
* 希尔排序
6+
*
7+
* @author LuoHaiYang
8+
*/
9+
public class ShellSort {
10+
public static void sort(int[] arr) {
11+
int n = arr.length;
12+
13+
int h = 1;
14+
15+
while (h < n / 3) {
16+
h = 3 * h + 1;
17+
}
18+
19+
while (h >= 1) {
20+
for (int i = h; i < n; i++) {
21+
int e = arr[i];
22+
int j = i;
23+
for (; j >= h && e < arr[j-h]; j -= h) {
24+
arr[j] = arr[j-h];
25+
}
26+
arr[j] = e;
27+
}
28+
29+
h /= 3;
30+
}
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /