1 #include<iostream>
2 using namespace std;
3 int pt[1000001];
4 void shell(int*,int);
5 void insert(int*,int,int,int);
6 int main() //shell排序
7 {
8 int num,L,i=0;
9
10 while(cin>>num)
11 {
12 pt[i++]=num;
13
14 if(cin.get()=='\n') break;
15 }
16 L=i;
17
18 shell(pt,L);
19 insert(pt,0,1,L); //易遗漏
20
21
22 for(i=0;i<L;i++)
23 cout<<pt[i]<<" ";
24 }
25
26 void shell(int*pt,int n) //shell排序
27 {
28 for(int i=n/2;i>=2;i/=2) //注意i=2(而课本上的没有(error))
29 for(int j=0;j<i;j++)
30 insert(pt,j,i,n);
31 }
32
33
34 void insert(int*pt,int left ,int gap,int n )
35 {
36 int i,j,num;
37 for( j=left+gap;j<n;j+=gap)
38
39 for( i=j;i>left;i-=gap)
40 if(pt[i-gap]>pt[i])
41 {
42 num=pt[i];pt[i]=pt[i-gap];pt[i-gap]=num;
43 }
44 }