希尔排序

前端之家收集整理的这篇文章主要介绍了希尔排序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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]+",");
    }
}

}

希尔排序又称缩小增量法,属于插入类排序。是将无序序列分割成若干小的子序列,然后进行插入排序。

希尔排序间隔序列函数:h = 1;if(h < lenght / 3 );h = h * 3 + 1;

原文链接:https://www.f2er.com/note/422298.html

猜你在找的程序笔记相关文章