希尔排序_Shell Sort

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/koreyoshi_chm/article/details/77804039

要点:

  1. 希尔排序是一种增量插入的排序方
  2. 在代码的实现过程中初始增量的设置选为序列的一般,然后依次减半,知道为1.
代码:

 
template<class T>
void shell_sort(T*s,int n)
{
    T temp;
    int i,j,h;
    for( h=n/2;h>0;h=h/2)
    {
       for( i=h;i<n;i++)
           {
             temp = s[i];
	     for(j=i-h;j>=0&&temp<s[j];j=j-h)
		{
		 s[j+h]=s[j];
		}
		 s[j+h] = temp;
		}
	}
}

猜你喜欢

转载自blog.csdn.net/koreyoshi_chm/article/details/77804039