您的位置:首页 > 其它

希尔排序1.0

2015-08-13 13:05 204 查看
<span style="font-family:Comic Sans MS;font-size:18px;">//shellSort.h
#include<iostream>
#include<vector>
using namespace std;
template<typename T>
void shellSort(vector<T> &v){
	int gap;//步长
	int n=v.size();//大小
	for(gap=n/2;gap>0;gap=gap/2){
		for(int j=0;j<gap;j++){
			for(int k=gap+j;k<=(n-1);k+=gap){
				for(int m=k;m>j;m=m-gap){
					if(v[m-gap]>v[m])
						swap1(v[m],v[m-gap]);
				}
			}
		}
	}	
}
template<typename T>
void swap1(T & a,T & b){
	auto temp=b;
	b=a;
	a=temp;
}
template<typename T>
void show(vector<T> & v){
	for(auto p:v)
		cout<<p<<endl;
}</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: