zoukankan      html  css  js  c++  java
  • 数据结构之shell排序

     #SIZE  10
           //直接插入排序 
       void insert_sort(){
              int i,j;
              int array[SIZE+1];
              array[]={0,12,23,11,55,2,34,18,20,48,22};
              for(i=2;i<=SIZE;i++){
                  array[0]=array[i];
                  j=i-1;
                  while(array[0]<array[j]){
                         array[j+1]=array[j];
                         j--;
                   }
                  array[j+1]=array[0];
                 }
          }
          //折半插入排序
        void insert_binary_sort(){
                   int j,i,low,hight,m;
                   int array[SIZE+1];
                 for(i=2;i<=SIZE;i++){
                     array[0]=array[i];
                     hight=i-1;
                     low=1; 
                    while(low<=hight)
                         {
                            m=(low+hight)/2;
                            if(array[0]<array[m])
                                 hight=m-1;
                            else low=m+1;
                          }
                     for(j=i;j>hight+1;j--)
                        {
                              array[j]=array[j-1];
                        }
                        array[hight+1]=array[0];
                   }
                  
        }
                
            //shell排序,在直接插入排序上进行优化而来
             void shell_sort(){
                 int d,n,j,i;
                 int array[SIZE+1];
                 int d=n;
                 do{
                     d=d/2;
                     for(i=d+1;i<=SIZE;i++)
                       {
                          array[0]=array[i];
                          for(j=i-d;j>0&&array[j]>array[0];j-=d){
                                array[j+d]=array[j];
                              }
                              array[j+d]=array[0];
                        }
                 }while(d!=1);
             }
  • 相关阅读:
    redis数据同步之redis-shake
    spring拦截机制中Filter(过滤器)、interceptor(拦截器)和Aspect(切面)的使用及区别
    MySQL之MVCC与幻读
    Notepad
    mac环境,python+selenium环境搭建,解决chromedriver报错问题
    大规模抓取的抓取效率和抓取技巧问题
    安卓逆向8,解决app抓包抓不到的问题
    [loj6033]棋盘游戏
    [ccBB]Billboards
    [loj6051]PATH
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6783349.html
Copyright © 2011-2022 走看看