久草最新视频-久草最新网址-久国产-久国产视频-天天插夜夜操-天天插一插

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

北京北大青鳥校區

北大青鳥網上報名
北大青鳥招生簡章
主站蜘蛛池模板: 亚洲另在线日韩综合色| 亚洲欧美综合一区二区三区四区| 日本一二三区视频| 色综合久久88一加勒比| 婷婷天堂| 天天操天天操天天| 三级黄色片在线播放| 青青操夜夜操| 午夜在线视频观看版| 人人爱人人搞| 人妖videosex人妖xxx| 欧美日韩精品| 亚洲激情视频在线| 亚洲毛片免费视频| 日韩经典在线| 青青青国产在线观看免费网站| 色综合小说久久综合图片| 青青青草视频| 网友自拍视频精品区| 日韩亚色| 亚洲一区在线免费| 日本黄色影片在线观看| 亚洲国产一区二区三区在线观看| 日本成人在线视频网站| 亚洲另类激情专区小说婷婷久| 四虎综合| 欧美久在线观看在线观看| 亚洲爆操| 奇米四色综合久久天天爱| 午夜欧美成人久久久久久| 天天综合色天天综合| 一级毛片一级片| 四虎国产精品免费五月天| 亚洲热色| 天天综合在线观看| 亚洲精品国产成人99久久| 天堂网亚洲| 日韩免费精品视频| 污片在线免费观看| 天天天做天天天天爱天天想| 日韩精选|