public class ShellSort {
public static void main(String
[] args
) {
int[] arr
= new int[]{9, 2, 56, 1, 3, 43, 21, 6, 12, 43, 3242, 55, 22, 553, 6542, 4, 7, 345, 234, 5, 33};
shellSort(arr
);
System
.out
.println(Arrays
.toString(arr
));
}
public static void shellSort(int[] arr
) {
for (int d
= arr
.length
/ 2; d
> 0; d
/= 2) {
for (int i
= d
; i
< arr
.length
; i
++) {
int temp
= arr
[i
];
int j
;
for (j
= i
- d
; j
>= 0 && arr
[j
] > arr
[j
+ d
]; j
-= d
) {
arr
[j
+ d
] = arr
[j
];
}
arr
[j
+ d
] = temp
;
}
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-9422.html