给定一个增量d,按这个增量分组,每组相邻元素的下标之差为d,每组做直接插入排序;增量按给定算法减少,每一次减少,重复上述步骤;直到增量减到1为止,得到一个有序序列
public int[] sort(int[] numbers) { int temp; int len = numbers.length; // 增量 int d; int j; for (d = len / 2; d > 0; d = d / 2) { for (int i = d; i < len; i += d) { temp = numbers[i]; for (j = i; j > 0 && temp < numbers[j - d]; j -= d) { numbers[j] = numbers[j - d]; } numbers[j] = temp; } } return numbers; }