希尔排序
来源:互联网 发布:台州学院网络教学平台 编辑:程序博客网 时间:2024/05/24 06:53
转自:http://blog.csdn.net/21aspnet/article/details/1534410
- #include <stdio.h>;
- void Shell_Sort(int a[], int n)
- {
- int h,i,j,temp; //h为间隔,temp暂存要插入的数据项
- //分为由粗到细的插入排序,这是希尔相对插入排序的特色。
//共要完成(log2 n)次的插入排序,每次需排序的长度加1,每次插入排序要插入count-h 个数据 - for (h=n/2; h>0; h=h/2) // 1/2 = 0 这时就会跳出循环-----获取间隔,同一间隔的为一大组
- {
- //先将从h 开始的以后的数按照插入排序一一插入从前面以h 为间隔选出的小组中,
//完成一次粗排序,粗细程度由间隔h 决定! - for (i=h; i<n; i++) //移动获取新的插入项------ ,移动扫描,获取新的数据项和大组数据( h之前的即为大组)
- {
- //特殊的插入排序,并不是一个个的比较然后移动,而是以h 为间隔的比较、移动和插入a[i]
- temp = a[i]; //暂存要插入的数据项,此插入数据项是不断向后移动的
- for (j=i-h; j>=0 && temp < a[j]; j-=h) //取分组
- {
- a[j+h] = a[j]; //a[i]移到后面
- }
- a[j+h] = temp;
- }
- }
- }
- int main(void)
- {
- int arr[]={1,5,2,4,3,8,6,7,9};
- int count=sizeof(arr)/sizeof(int);
- Shell_Sort(arr,count);
- int k;
- for(k=0;k<count;k++)
- {
- printf("%d",arr[k]);
- }
- return 0;
- }
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- Oracle Goldengate特别有用的几个处理数据方法
- POJ 3734 Blocks【用母函数推公式|矩阵乘法】
- LUA面向对象程序设计(三)多态
- JS,判断对象是否具有指定的方法?
- Android控件之HorizontalScrollView代替Gallery
- 希尔排序
- HDU2082
- LUA面向对象程序设计(四)多重继承
- 雷德为您展现立式锯床的特色
- C++多态性1
- Java Web开发简介(章节摘要)
- Ubuntu 14.04 LTS下安装 LNMP环境
- FrameLayout measure过程源码Log全解析之二:修改framework代码,输出Log
- SQlServer 安装出错:未指定 INSTANCESHAREDWOWDIR 命令行值