栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【希尔排序 c++】

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【希尔排序 c++】

**

希尔排序 C++

**

这里就不讲原理了,原理大家都懂,就是不会敲代码 //泪目了//

#include 

#include 

using namespace std;

#define Max 500    

 

void ShellSort(int R[],int N,int d[],int t);

void Print(int R[],int N);

 

int  main()

{

    int *R,N,i,*d,t;                     

    cin>>N;

    R=new int[N+1];

    for(i=1; i<=N; i++)

        cin>>R[i];

    Print(R,N);

    cin>>t;

    d=new int[t];

    for(i=0; i>d[i];

    ShellSort(R,N,d,t);

    Print(R,N);

    return 0;

}

 

void Print(int R[],int N)

{

    int i;

    cout<
	for(int i=0;i//d[i]为增量 
		for(int j=1;j<=d[i];j++)//增量为几就有几个序列 
		{
			for(int k=j;k<=N-d[i];k+=d[i]){//分好了每个序列,现在要用直接排序 //从后往前移动 主要是要想清楚分组的边界 
			int end=k;//最后的那个数 
			int tmp=R[end+d[i]];//待插入的数 
			while(end>=1){//数组从1开始放 
				if(tmp//交换 
					R[end+d[i]]=R[end];
					end-=d[i];
				}else break;
			}
			R[end+d[i]]=tmp;	
			}
		}
		Print(R,N);
	 } 
}

如果看不懂中间两个循环的话,建议去补一下插入排序
记录一下做题,如果有更好的建议欢迎提出来呀!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/974974.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号