掐指一算----希爾排序--2019年07月13日

public static void main(String[] args) {
        int[] arrs = {4,2,9,5,7,1,0};
        shellSort(arrs);
        for(int a:arrs){
            System.out.println(a);
        }


    }
    public static void shellSort(int[] arrs){
        int n,detla,i;
        n = arrs.length;
        for(detla = n/2;detla>0;detla/=2){
            for( i=0;i<detla;i++){
                modInsSort(arrs, n-i,detla);

            }
        }

    }
    public static void modInsSort(int[]arrs,int n, int detla){
        for(int i=detla;i<n;i+=detla) {
            for ( int j = i; j >= detla; j -= detla) {
                if(arrs[j]<arrs[j-detla]){
                    int temp = arrs[j];

                    arrs[j] = arrs[j-detla];
                    arrs[j-detla] = temp;
                }else{
                    break;
                }
            }
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章