希尔排序(Java语言)

 视频讲解地址:【手把手带你写十大排序】3.希尔排序(Java语言)_哔哩哔哩_bilibili

代码:

public class ShellSort {
    public void sortFunction(int[] array) {
        int gap = array.length;
        while (gap > 1) {
            int i, j;
            gap = gap >> 1;
            for (i = 0; i < array.length - gap; i++) {
                int temp = array[i + gap];
                for (j = i; j >= 0; j -= gap) {
                    if (temp < array[j]) {
                        array[j + gap] = array[j];
                    } else {
                        break;
                    }
                }
                array[j + gap] = temp;
            }
        }
    }
}

你可能感兴趣的:(java,python,算法)