希尔排序基础实现-创新互联
#include
using namespace std;
void ShellSort(int *a,int length)
{
if (a == NULL || length <= 0)
{
return;
}
int gap = length;
while (gap != 1)
{
if (gap > 1)
{
gap = gap / 3 + 1;
}
for (int begin = gap; begin < length; begin += gap)
{
int index = begin;
int tmp = a[begin];
while (index)
{
if (tmp < a[index - gap])
{
a[index] = a[index - gap];
}
else
{
break;
}
index -= gap;
}
if (tmp < a[index])
{
a[index] = tmp;
}
}
}
}
void SellSortTest()
{
int a[] = { 3, 6, 2, 8, 1, 5, 9, 4, 7, 0 };
ShellSort(a, 10);
for (int i = 0; i < sizeof(a) / sizeof(a[0])-1; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
int main()
{
SellSortTest();
return 0;
}
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
当前文章:希尔排序基础实现-创新互联
文章网址:http://myzitong.com/article/gsgsj.html