希尔排序

来源:互联网 发布:linux 删除匹配文件 编辑:程序博客网 时间:2024/05/21 00:56
 static void shellSort1(Integer[] sortList) {
        int i, j, step;
        int len = sortList.length;
        // 步长除以2
        for (step = len / 2; step > 0; step /= 2)
            /**
            *  分别对每个分组进行直接插入排序
            */
            for (i = 0; i < step; i++) 
            {
                for (j = i + step; j < len; j += step)
                    if (sortList[j] < sortList[j - step]) {
                        int temp = sortList[j];
                        int k = j - step;
                        while (k >= 0 && sortList[k] > temp) {
                            sortList[k + step] = sortList[k];
                            k -= step;
                        }
                        sortList[k + step] = temp;
                    }
            }
    }
0 0
原创粉丝点击