天天看点

shell排序基本思想及其复杂度分析

public static void shellSort ( int[] a){
            int len = a.length;
            int h = 1;
            while (h < len / 3)
                h = h * 3 + 1;
            while (h > 0) {
                for (int i = h; i < len; ++i) {
                    for (int j = i; j >= h; j = j - h) {
                        if (a[j] < a[j - h]) {
                            int temp = a[j];
                            a[j] = a[j - h];
                            a[j - h] = temp;
                        }
                    }
                }
                h = h / 3;
            }

        }
           

Ps:博文为博主的学习笔记,算法只是按照自己的理解简单分析,初学者建议看详细的图文讲解,如果有错误,欢迎交流指正