希尔排序
来源:互联网 发布:知己知彼软件破解版 编辑:程序博客网 时间:2024/05/16 04:56
该方法实质上是一种分组插入方法。把记录按下标的一定增量分组,对每组使用直接插入排序算法排序;
随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止。
void insertSort(int *data,int count,int startIndex,int step);void shellSort(int *data,int count);unsigned int getMin2Pow(int count);unsigned int getMin2Pow(int count) {unsigned int tmp;unsigned int result = (count >> 1);for(tmp = result >> 1;tmp > 0;tmp >>= 1){result |= tmp;}return result;}void shellSort(int *data,int count) {int step;int startIndex;for(step = getMin2Pow(count);step > 0;step >>= 1){for(startIndex = 0;startIndex < step;startIndex++) {insertSort(data,count,startIndex,step);}}}void insertInsert(int *data,int count,int startIndex,int step) {int i;int j;int t;int temp;for(i = startIndex + step;i < count;i += step) {temp = data[i];for(j = startIndex;j < i && data[j] <= data[i];j += step);for(t = i - step;t >= j;t -= step) {data[t+step] = data[t];}data[j] = temp;}}
0 0
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 希尔排序
- 求多边形包围区域
- 在mac上搭建python 环境
- 排序——插入排序
- Torch7入门续集(六)----多GPU运行程序
- Android填坑之旅(第三篇) 关于Android 最有效的隐藏软键盘方法
- 希尔排序
- Buy the Ticket
- 利用MarqueeTextView实现上下公告栏并点击进行相应跳转
- LintCode-在O(1)时间复杂度删除链表节点
- javascript之内置对象
- 【数据结构】——-栈、队列和数组(一)
- 存储过程与存储函数
- 在O(1)时间复杂度删除链表节点
- Hat's Fibonacci