#include <stdio.h>
#include <string.h>
#include <math.h>
int shell_sort(int s[],int n)
{
int i,j,temp,d;
float a,b;
//int p;
b=n;
a=b/2;
//printf("%f\n",a);
for(d=ceil(a);d>=1;d=ceil(a)) //d is the increasing range
{
for(i=d;i<n;i++)
{
j=i; //the num before
temp=s[j-d];
while(j<n&&temp>s[j])
{
s[j-d]=s[j];
j=j+d;
}
s[j-d]=temp;
a=(d)/2;
/*for(p=0;p<n;p++)
{
printf("%d ",s[p]);
}
printf("\n");*/
}
//printf("%d\n%f\n",d,a);
}
return *s;
}
int main()
{
int s[5];
int n,i;
n=5;
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
}
shell_sort(s,n);
for(i=0;i<n;i++)
{
printf("%d ",s[i]);
}
}
经典排序——希尔排序——C语言版
最新推荐文章于 2022-09-25 12:10:08 发布