`
meikebo
  • 浏览: 16047 次
社区版块
存档分类
最新评论

插入排序--希尔排序

阅读更多
一,方法一
public void shellSort1(int[] a)
	{
		int d=a.length/2;
		int temp;
		int j;
		while(d>=1)
		{
			for(int m=0;m<d;m++)
			{
				for(int i=d+m;i<a.length;i=i+d)
				{
					temp=a[i];
					for(j=i-d;j>=0 && a[j]>temp;j=j-d)
						a[j+d]=a[j];
					a[j+d]=temp;
				}
			}
			d=d/2;
		}
	}

二,方法二
public void shellSort(int[] a)
	{
		int d=a.length/2;
		int temp;
		while(d>=1)
		{
			for(int k=0;k<d;k++)
			{
				for(int i=d+k;i<a.length;i=i+d)
				{
					for(int j=i-d;j>=0;j=j-d)
					{
						if(a[i]<a[j])
						{
							temp=a[i];
							for(int m=i-d;m>=j;m=m-d)
								a[m+d]=a[m];
							a[j]=temp;
						}
					}
				}
			}
			d=d/2;
		}
	}

数据结构排序算法,C++版,参看地址http://www.cnblogs.com/mingcn/archive/2010/10/17/Sort.html#4
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics