public static void shellSort(int[] arrays) {
for (int d = 5; d > 0; d = d - 2) {
for (int c = 0; c < arrays.length - d; c++) {
for (int i = c; i < arrays.length; i = i + d) {
for (int j = i; j > 0; j = j - d) {
if (j < d) break;
if (arrays[j] < arrays[j - d]) {
int tmp;
tmp = arrays[j];
arrays[j] = arrays[j - d];
arrays[j - d] = tmp;
}
}
}
}
}
}
public static void main(String[] args) {
int[] arr = {45,20,80,40,26,58,66,70};
shellSort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+",");
}
}
}
原文链接:https://www.f2er.com/note/422298.html希尔排序又称缩小增量法,属于插入类排序。是将无序序列分割成若干小的子序列,然后进行插入排序。
希尔排序间隔序列函数:h = 1;if(h < lenght / 3 );h = h * 3 + 1;