# include "stdio.h"
# include "malloc.h"
void ShellSort (int * a, int n) //希尔排序
{
int stride = n / 2 ;
int i, j ;
int iVal ;
for (stride = n / 2 ; ; stride = stride / 3 + 1)
{
for (i = stride ; i < n ; i ++, a[j] = iVal)
for (iVal = a[i], j = i ; j >= stride && iVal < a[j - stride] ; j -= stride)
a[j] = a[j - stride] ;
if (stride == 1)
break ;
}
}
// void ShellSort (int * a, int n) //牛人写的不明算法
// {
// int step = n / 2 ;
// int inner = 0;
// int outer = 0;
// int median = 0;
// int index ;
//
// for(; step >= 1; step -=2)
// {
// for(index = 0; index < step; index ++)
// {
// if((n -1) < (index + step))
// continue;
// else
// {
// outer = index + step;
// while( (outer + step) <= (n - 1))
// outer += step;
// }
//
// for(; outer >= (index + step); outer -= step)
// {
// for(inner = index; inner <= outer - step; inner += step)
// {
// if(a[inner] >= a[inner + step])
// {
// median = a[inner];
// a[inner] = a[inner + step];
// a[inner + step] = median;
// }
// }
// }
// }
// }
// }
int main ()
{
int n, i ;
int * a ;
printf ("Please input the number n : ") ;
scanf ("%d", &n) ;
a = (int *) malloc (n * sizeof (int)) ;
printf ("Please input :\n") ;
for (i = 0 ; i < n ; i ++)
{
scanf ("%d", a + i) ;
}
ShellSort (a, n) ;
for (i = 0 ; i < n ; i ++)
{
printf ("%d ", *(a + i)) ;
}
printf ("\n") ;
free (a) ;
return 0 ;
}