本文实例讲述了C语言基本排序算法之shell排序。分享给大家供大家参考,具体如下:
shell排序是对直接插入方法的改进方法.
#ifndef SHELL_SORT_H
#define SHELL_SORT_H
#include "typedef.h"
void Shell_sort(T* a, int n)
{
for(int gap = n; gap > 0; gap = gap/2)
{
for(int i = 0; i != n; ++i)
{
T temp = a[i];
int j = i - gap;
for( ; j >= 0 && a[j] > temp; j = j-gap)
a[j+gap] = a[j];
a[j+gap] = temp;
}
}
}
#endif
希望本文所述对大家C语言程序设计有所帮助。



