We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8b85e8e commit 0eaeb6bCopy full SHA for 0eaeb6b
1 file changed
algorithmBook/ShellSort.java
@@ -0,0 +1,29 @@
1
+/**
2
+ * Ëã·¨ - ºì±¦Êé
3
+ * Ï£¶ûÅÅÐò
4
+ */
5
+
6
+public class ShellSort {
7
+ public static int[] sortArray(int[] nums) {
8
9
+ for (int step = nums.length / 2; step > 0; step /= 2) {
10
+ for (int i = step; i < nums.length; i++) {
11
+ int tmp = nums[i];
12
+ int j = i;
13
+ for (; j >= step && nums[j-step] > tmp; j -= step) {
14
+ nums[j] = nums[j - step];
15
+ }
16
+ nums[j] = tmp;
17
18
19
+ return nums;
20
21
22
+ public static void main(String[] args) {
23
+ int[] nums = new int[]{5, 2, 3, 1};
24
+ sortArray(nums);
25
+ for(int i = 0; i < nums.length; i++) {
26
+ System.out.print(nums[i] + " ");
27
28
29
+}
0 commit comments