日本粉色视频-日本理论片中文在线观看2828-日本理论在线观看被窝网-日本黄大片在线观看-国产精品福利在线观看秒播-国产精品福利资源在线

北大青鳥北京,通州北大青鳥校區學術部:Java的排序之“希爾排序”

北京北大青鳥通州校區學術部老師講解:什么是希爾排序?

北京北大青鳥專家解答:希爾排序就是對插入排序的優化, 他是把一個待排序的數組分段成有規律的的若干個數組排序,最后在進行總排序來完成排序的目的,

基本思想:先取一個小于n的整數d1作為第一個增量,把文件的全部記錄分成d1個組。所有距離為d1的倍數的記錄放在同一個組中。先在各組內進行直接插入排序;然后,取第二個增量d2北大青鳥校區)


(1)將等間距的數組元素按升序排列(北京北大青鳥校區
view plaincopy to clipboardprint?
private static void incrementalInsertionSort(int[] array, int first,  
                      int last, int space)  
    {  
        int unsorted, index;  
        for (unsorted = first + space; unsorted <= last; unsorted += space)  
        {  
            int firstUnsorted = array[unsorted];  
            for (index = unsorted - space; (index >= first)   
                  && (firstUnsorted < array[index]); index -= space)  
            {  
                array[index+space] = array[index];  
            }  
            array[index+space] = firstUnsorted;  
        }  
    } 
private static void incrementalInsertionSort(int[] array, int first,
             int last, int space)
 {
  int unsorted, index;
  for (unsorted = first + space; unsorted <= last; unsorted += space)
  {
   int firstUnsorted = array[unsorted];
   for (index = unsorted - space; (index >= first)
         && (firstUnsorted < array[index]); index -= space)
   {
    array[index+space] = array[index];
   }
   array[index+space] = firstUnsorted;
  }
 }
2)設定索引間距序列(北京北大青鳥校區)
view plaincopy to clipboardprint?
public static void shellSort(int[] array, int first, int last)  
    {  
        int n = last-first + 1;  
        for (int space = n / 2; space > 0; space /= 2)  
        {  
            for (int begin = first; begin < first + space; begin++)  
            {  
                incrementalInsertionSort(array, begin, last, space);  
            }  
        }  
    } 
public static void shellSort(int[] array, int first, int last)
 {
  int n = last-first + 1;
  for (int space = n / 2; space > 0; space /= 2)
  {
   for (int begin = first; begin < first + space; begin++)
   {
    incrementalInsertionSort(array, begin, last, space);
   }
  }
 }
3)測試(北京北大青鳥校區
view plaincopy to clipboardprint?
public static void main(String[] args)  
    {  
        // TODO Auto-generated method stub  
        Random random = new Random();  
        final int size = 10;  
        int i;  
        int[] array = new int[size];  
        for (i = 0; i < size; i++)  
        {  
            array[i] = random.nextInt(1000);  
        }  
        System.out.println("排序前數組");  
        for (i = 0; i < size; i++)  
        {  
            if((i+1) % 20 == 0)  
            {  
                System.out.println();  
            }  
            else 
            {  
                System.out.print(array[i] + "  ");  
            }  
        }  
        shellSort(array,0,size-1);  
        System.out.println("\n排序后數組");  
        for (i = 0; i < size; i++)  
        {  
            if((i+1) % 20 == 0)  
            {  
                System.out.println();  
            }  
            else 
            {  
                System.out.print(array[i] + "  ");  
            }  
        }  
 
    }

北京北大青鳥校區

北大青鳥網上報名
北大青鳥招生簡章
主站蜘蛛池模板: 国产亚洲欧美日韩国产片 | 欧美性色网 | 久草国产视频 | 久久精品久久精品国产大片 | 亚洲国产日韩欧美一区二区三区 | 白嫩美女一级毛片免费看 | 日韩一级在线播放免费观看 | 色在线网站免费观看 | 成人国产一区二区三区精品 | 亚洲欧美日韩在线线精品 | 亚洲网视频| 久久精品久久精品 | 久99re视频9在线观看 | 九九大香尹人视频免费 | 亚洲毛片在线 | 美女擦逼| 91久久精品视频 | 香蕉依依精品视频在线播放 | 国产三级日本三级日产三级66 | 一区二区三区亚洲 | 看国产一级片 | 国产成人aa在线观看视频 | 色本道 | 久久香蕉国产线看观看亚洲片 | 亚洲视频欧美 | a级国产乱理伦片在线观看国 | 女人被男人躁得好爽免费视频免费 | 91色综合综合热五月激情 | 欧美一区二区三区久久久人妖 | 2022国产精品手机在线观看 | 国产不卡在线观看视频 | 亚洲高清视频在线播放 | 亚洲欧美日韩国产vr在线观 | 亚洲一区视频 | 日韩美女毛片 | 最新精品在线视频 | 欧美a大片 | 国产精品免费观看视频 | 长腿美女被啪的欲仙欲死视频 | 久久九九国产精品怡红院 | 韩国毛片在线 |