希尔排序
设置“监视哨”,写希尔排序,给出详细注释说明,求助各位!
设置“监视哨”,写希尔排序,给出详细注释说明,求助各位!
| 全能ASP/PHP/ASP.NET主机,支持月付 | 专业 MSSQL 数据库空间,支持月付 | 专业 MySQL 数据库空间,支持月付 | 学习型 ASP/PHP/ASP.NET 主机 30元/年 |
| 高端软件开发 = 年薪十万不是梦 |
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **
*****************************************************************/
#include<iostream>
#include<ctime>
const int MAXSIZE = 30;
int array[MAXSIZE];
void ShellSort(int (&array)[MAXSIZE],const int left,const int right)
{
int gap = right-left+1; //增量的初始值
do
{
gap = gap/3 + 1; // 求下一增量
for (int i=left+gap;i<=right;i++) //各子充列交错处理
if (array[i] < array[i-gap]) //逆序
{
int temp = array[i], j = i-gap;
do
{
array[j+gap] = array[j]; //后移元素
j = j-gap; //现比较前一元素
}while (j>left &&temp < array[j]);
}
}while (gap > 1);
}
int main(void)
{
srand(unsigned(time(NULL)));
for (int i=0;i<MAXSIZE;i++)
array[i] = rand()%10000;
std::cout<<std::endl<<"***希尔排序(SHELL SORT)***"<<std::endl;
ShellSort(array,0,MAXSIZE);
display(array,MAXSIZE);
return 0;
}

