We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 584645b commit 50c699aCopy full SHA for 50c699a
src/com/fantasy/algorithm/sort/ShellSort.java
@@ -17,7 +17,7 @@
17
*
18
* <pre>
19
* author : Fantasy
20
- * version : 1.0, 2020-08-31
+ * version : 1.1, 2020-09-04
21
* since : 1.0, 2020-08-31
22
* </pre>
23
*/
@@ -34,14 +34,12 @@ public static void shellSort(int[] arr) {
34
int length = arr.length;
35
int value; // 待插入的值
36
int step = length / 2; // 记录每一次跳跃式比较的增量
37
+ int j;
38
while (step >= 1) {
39
for (int i = step; i < length; i += step) {
40
value = arr[i];
- int j = i;
41
- // 注意点,与插入排序不同的是这里要">=",因为step最小为1
42
- while (j >= step && arr[j - step] > value) {
+ for (j = i; j >= step && arr[j - step] > value; j -= step) {
43
arr[j] = arr[j - step];
44
- j -= step;
45
}
46
arr[j] = value;
47
0 commit comments