private int[] data = new int[]{ 4, 105, 91, 2, 38, 6, 7, 3, 11, 9}; /** * shell排序 * 时间复杂度O(n^2) * 空间复杂度O(1) */ @Test public void sheelTest() { int j = 0; int min = 0; for (int step = data.length / 2; step > 0; step /= 2) { for (int i = step; i < data.length; i++) { min = data[i]; for (j = i; j >= step; j -= step) { if (min < data[j - step]) { data[j] = data[j - step]; } else { break; } } data[j] = min; } } System.out.println(Arrays.toString(data));
}