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 }

 

posted @ 2015-11-13 21:33  指间ゝ繁华初逝的格调  阅读(170)  评论(0编辑  收藏  举报