希尔排序

#include<stdio.h>

void ShellSort(int array[],int length)
{
    int i,j,h,temp;
    for(h=length/2;h>0;h=h/2)
    {
        for(i=h;i<length;i++)
        {
            temp=array[i];
            for(j=i-h;j>=0;j-=h)
            {
                if(temp<array[j])
                {
                    array[j+h]=array[j];
                }
                else break;
            }
            array[j+h]=temp;
        }
    }
}

int main()
{
    int a[]={3,1,5,3,4,7,1};
    ShellSort(a,7);
    for(int i=0;i<7;i++) printf("%d ",a[i]);
    return 0;
}

  

原文地址:https://www.cnblogs.com/zsboy/p/3946661.html