天天看點

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:博文為部落客的學習筆記,算法隻是按照自己的了解簡單分析,初學者建議看詳細的圖文講解,如果有錯誤,歡迎交流指正