希尔排序_Shell Sort

来源:互联网 发布:itc网络广播功放说明书 编辑:程序博客网 时间:2024/06/14 09:38

要点:

  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;}}}
原创粉丝点击