欧美一级内谢_91中文字幕在线_羞羞视频官网_亚洲日韩中文字幕天堂不卡_在线观看日韩一区_国产成人激情

北大青鳥北京,通州北大青鳥校區學術部: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] + "  ");  
            }  
        }  
 
    }

北京北大青鳥校區

北大青鳥網上報名
北大青鳥招生簡章
主站蜘蛛池模板: 99在线免费视频 | 一区二区三区四区在线 | 免费天天干 | 久久精品亚洲精品 | 一区二区中文 | 亚洲天堂色 | 国产成人综合一区二区三区 | 本道综合精品 | 久久大| 黄色视频a级毛片 | 欧美乱做爰xxxⅹ久久久 | 蜜桃av一区二区三区 | 中文字幕精品一区 | 6080亚洲精品一区二区 | 97伦理影院 | 亚洲视频国产视频 | 成人一区二区三区 | 国产精品99久久久精品免费观看 | 欧美精品 在线观看 | 国产伦精品一区二区三区精品视频 | 日本在线视频一区二区 | 久久精品中文 | 自拍偷拍亚洲一区 | 久久网国产| 成人av在线播放 | av色噜噜| 紧缚调教一区二区三区视频 | 亚洲成人精品影院 | 91精品国产综合久久小仙女图片 | 亚洲免费观看视频网站 | 精品日韩在线 | 亚洲久久 | 中文字幕日韩一区 | 亚洲精品视频一区 | 精品欧美二区 | 精品国产一区二区三区日日嗨 | 亚洲精品久| caoporn国产| 日本亚洲精品成人欧美一区 | 国产精品乱码一区二三区小蝌蚪 | 麻豆av在线免费观看 |