zoukankan      html  css  js  c++  java
  • 8)排序③排序算法之插入排序[2]希尔排序

     1 #include<iostream>
     2 using namespace std;
     3 
     4 int shell_sort(int n,int array[100]){//希尔排序法
     5     register int dh,temp,i,j;
     6     dh=n/2;
     7     while(dh>=1){
     8         for( i=dh;i<n;i++){
     9             temp=array[i];
    10             j=i-dh;
    11             while(j>=0&&array[j]>temp){
    12                 array[j+dh]=array[j];    
    13                 j-=dh;
    14             }
    15             array[j+dh]=temp;
    16         }
    17         dh/=2;
    18     }
    19     return 0;
    20 }
    21 int print(int n,int array[100]){
    22     int i;
    23     for(i=0;i<n;i++){
    24         cout<<array[i]<<" ";
    25     }
    26     cout<<endl;
    27     return 0;
    28 }
    29 int main()
    30 {
    31     int array[10]={5,7,8,2,3,5,4,3,2,1};
    32     shell_sort(10,array);
    33     print(10,array);
    34     return 0;
    35 }
  • 相关阅读:
    5-29
    5-28
    5-27
    -5-26
    5-25
    5-24
    5-21
    RabbitMQ消息中间件极速入门与实战
    细说java多线程之内存可见性
    全面解析java注解
  • 原文地址:https://www.cnblogs.com/minmsy/p/4963301.html
Copyright © 2011-2022 走看看