设为首页 加入收藏

TOP

希尔排序
2014-11-24 00:36:34 来源: 作者: 【 】 浏览:28
Tags:希尔 排序
#include "stdafx.h"
#include
using namespace std;

//希尔算法(升序)
void InsertSort(int a[], int n)
{
int h,i,j,temp;
for (h=n/2; h>0; h=h/2)
{
for (i=h; i {
temp = a[i];
for (j=i-h; j>=0 && temp < a[j]; j-=h)
{
a[j+h] = a[j];
}
a[j+h] = temp;
}
}

}

//输出数组 www.2cto.com
void Print_Arry(int a[], int n)
{
for (int i=0; i {
cout<< a[i]<<" ";
}
cout< }

int _tmain(int argc, _TCHAR* argv[])
{
int a[9] = {7,3,5,8,9,1,2,4,6};
InsertSort(a, 9);
Print_Arry(a, 9);
return 0;
}

摘自 学无止境
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇EOF与feof()函数关系 下一篇直接插入排序算法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: