排序算法之希尔排序(java代码)

希尔排序

public class ShellSort {
    public static void main(String[] args) {
    }
    public static void sort(int[] array) {
        int l = array.length;
        for (int gap = l / 2; gap > 0; gap /= 2) {
            for (int i = gap; i < l; i++) {
                for (int j = i - gap; j >= 0; j -= gap) {
                    if(array[j] > array[j + gap]) {
                        int temp = array[j];
                        array[j] = array[j + gap];
                        array[j + gap] = temp;
                    }
                }
            }
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/yonezu/p/11973265.html