时间复杂度:O(n*n)
空间复杂度:O(1)
https://www.cnblogs.com/snowcan/p/6244391.html
//分成多个组的插入排序
public void shellSort(int[] number) {
int n = number.length;
for (int gap = n / 2; gap > 0; gap /= 2) {
for (int i = 0; i < gap; i++) {
for (int j = i + gap; j < n; j += gap) {
if (number[j] < number[j - gap]) {
int tmp = number[j];
int k = j - gap;
while (k >= 0 && number[k] > tmp) {
number[k + gap] = number[k];
k -= gap;
}
number[k + gap] = tmp;
}
}
}
}
}
优化
public static void shell2Sort(int[] number){
int length=number.length;
int k;
for(int gap = length/2; gap >0 ; gap/=2) {
for(int i = 0; i <gap ; i++) {
for(int j = i+gap; j <length; j+=gap) {
int tmp=number[j];
for(k = j-gap; k >=0&&number[k] >tmp; k-=gap) {
number[k+gap]=number[k];
}
number[k+gap]=tmp;
}
}
}
}