#include <bits/stdc++.h>
using namespace std;
int pp[10010];
int main()
{
int n;
while(cin >> n)
{
int i;
for( i = 0; i < n; i++)
{
scanf("%d", &pp[i]);
}
for(int d = n/2; d > 0; d/=2)//希尔增量序列
{
for(int p = d; p < n; p++)//插排
{
int tmp = pp[p];
for(i = p; i >= d && pp[i-d] > tmp; i -= d)
pp[i] = pp[i - d];
pp[i] = tmp;
}
if(d == n/2)
{
for(int j = 0; j < n; j++)
{
(j == 0) ? cout << pp[j]: cout << ' ' << pp[j];
}
cout << endl;
}
}
for(i = 0; i < n; i++)
{
(i == 0) ? cout << pp[i]: cout << ' ' << pp[i];
}
cout << endl;
}
return 0;
}
SDUT 3403 数据结构实验之排序六:希尔排序
最新推荐文章于 2020-04-08 21:15:02 发布