//ShellSort
#include<stdio.h>
#include<stdlib.h>
#define N 10
void ShellSort(int array[],int length);
int main()
{
int i;
int array[N]={3,8,2,5,9,4,50,30,96,54};
ShellSort(array,10);
for(i=0;i<N;i++)
printf("%d ",array[i]);
return 0;
}
//排序
void ShellSort(int array[],int length)
{
int i,j;
int step=length; //步长step
int temp; //临时变量
for(step=length/2;step>0;step/=2)
{
for(i=step;i<length;i++)
{
temp=array[i];
for(j=i-step;(j>=0)&&(array[j]>temp);j-=step)
array[j+step]=array[j];
array[j+step]=temp;
}
}
}
希尔排序ShellSort
最新推荐文章于 2022-07-14 19:36:19 发布