C++希尔排序算法代码
template<class T>
void ShellSort(T arr[], int N)
{
inti;
intj;
intstep;
for( step = N/2; step > 0; step/=2)
{
for(i= step; i < N; i++) //注意此处递增的步长为1,依次比较!
{
for(j= i-step; j >=0 && arr[j+step] < arr[j]; j-=step)
{
swap(arr[j+step],arr[j]);
}//endfor j
}//endfor i
}//endfor step
}
