#include <iostream>
#include<bits/stdc++.h>
using namespace std;
void ShellInsert(int a[],int dt,int length){
int t,j;
for(int i=dt;i<length;i++)
if(a[i]<a[i-dt]){
t=a[i];
for(j=i-dt;j>=0&&a[j]>t;j=j-dt)
a[j+dt]=a[j];
a[j+dt]=t;
}
}
void ShellSort(int a[],int dt[],int t,int length){
for(int i=0;i<t;i++){
ShellInsert(a,dt[i],length);
}
}
int main()
{
int a[100];
int dt[3]={
5,3,1};
int x,i=0;
cin>>x;
while(x){
a[i++]=x;
cin>>x;
}
ShellSort(a,dt,3,i);
for(int j=0;j<=i-1;j++)
cout<<a[j]<<" ";
//cout << "Hello world!" << endl;
return 0;
}
8547 Hill Sort
Guess you like
Origin blog.csdn.net/changbaishannefu/article/details/111648241
Recommended
Ranking