首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

这是ShellSort吗?为啥如何诡异

2012-10-12 
这是ShellSort吗?为啥怎么诡异?void ShellSort(int a[], int n){int d nwhile(d 1) {d (d+1)/2for

这是ShellSort吗?为啥怎么诡异?
void ShellSort(int a[], int n)
{
int d = n;
while(d > 1) {
d = (d+1)/2;
for(int i = 0; i < n-d; i++) {
if(a[i+d] < a[i]) {
int tmp = a[i+d];
a[i+d] = a[i];
a[i] = tmp;
}
}
}
}//O(n^1.25)

大家觉得对么? 这个希尔排序

[解决办法]
希尔排序是对分组内存有的数排序,而不是对相隔为d的两个数两两排序,思路是错的。
如数据 int a[9]={8,7,9,3,2,4,5,6,1};

为了找到错误数据,我还写了个测试程序。。
[解决办法]
希尔排序,可以看看我的这篇文章
http://blog.csdn.net/kuzuozhou/article/details/7974440

热点排行