#include<stdio.h>
void ShellInsert(int L[], int dk, int length)//插入函数
{
int i, j;
for(i = dk + 1; i <= length; i++)
{
if(L[i] < L[i - dk])
{
L[0] = L[i];
for(j = i - dk; j > 0 && L[0] < L[j]; j -= dk)
{
L[j + dk] = L[j];
}
L[j + dk] = L[0];
}
}
}
void ShellSort(int L[], int dlta[], int t, int length)//希尔排序
{
int k;
for(k = 0; k < t; k++)
{
ShellInsert(L, dlta[k], length);
}
}
int main()
{ int dlta[3] = {5, 3, 1};//增量取5,3,1
int L[100];
int i;
L[1] = 49;
L[2] = 38;
L[3] = 65;
L[4] = 97;
L[5] = 76;
L[6] = 13;
L[7] = 27;
L[8] = 49;
L[9] = 55;
L[10] = 4;
ShellSort(L, dlta, 3, 10);
for(i = 1; i <= 10; i++)
{
printf("%d ",L[i]);
}
return 0;
}
希尔排序(C语言实现)
最新推荐文章于 2023-06-30 16:25:12 发布