@Test
public void shellSort() {
int[] array = {7, 3, 2, 9, 15, 1, 14};
for (int increment = array.length / 2; increment > 0; increment /= 2) {
for (int i = increment; i < array.length; i++) { //循环每个组内排序
int temp = array[i];
int j = 0;
for (j = i; j>= increment; j -= increment) {
if (temp < array[j - increment]) { //元素进行判断交换
array[j] = array[j - increment];
} else {
break;
}
}
array[j] = temp;
}
}
for (int i = 0; i < array.length; i++) { //循环输出重新排序的结果
System.out.println(array[i]);
}
}