數據結構與算法(希爾排序)

希爾排序其實就是插入排序的優化版本

void ShellSort(int *a,int n)
{
    int i,j,temp;
    int gap = n/2;
    while(gap>1)
    {
        for(i=gap;i<n;i=i++)
        {
            temp = a[i];
            for(j=i-gap;j>=0 && a[j]<temp;j=j-gap)
            {
                a[j+gap] = a[j];
            }
            a[j+gap] = temp;
        }
        gap = gap / 2;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章