shell排序
来源:互联网 发布:mac怎么下载视频 编辑:程序博客网 时间:2024/05/21 11:30
shell排序是对插入排序的一个改装,它每次排序把序列的元素按照某个增量分成几个子序列,对这几个子序列进行插入排序,
然后不断的缩小增量扩大每个子序列的元素数量,直到增量为一的时候子序列就和原先的待排列序列一样了,此时只需要做少
量的比较和移动就可以完成对序列的排序了。
Best:n Average: nlong^2n or n^(3/2) Worst: Depends on gap sequence; best know is nlong^2n
Memory:1 Stable:No
// shell排序void ShellSort(int array[], int length){ int temp; // 增量从数组长度的一半开始,每次减小一倍 for (int increment = length / 2; increment > 0; increment /= 2) for (int i = increment; i < length; ++i) { int j; temp = array[i]; // 对一组增量为increment的元素进行插入排序 for (j = i; j >= increment; j -= increment) { // 把i之前大于array[i]的数据向后移动 if (temp < array[j - increment]) { array[j] = array[j - increment]; } else { break; } } // 在合适位置安放当前元素 array[j] = temp; }}
阅读全文
0 0
- shell排序
- shell排序
- SHELL排序
- Shell排序
- shell排序
- shell排序
- Shell 排序
- Shell排序
- Shell排序
- Shell排序
- shell 排序
- shell排序
- shell排序
- Shell排序
- Shell排序
- Shell排序
- Shell排序
- shell排序
- Docker(简介)
- [链表]
- 码出高效,码出质量:阿里Java开发手册正式发布!
- Nginx配置跨域-http请求方法OPTIONS
- 课程设计 栈之 后缀表达式求值 中缀表达式转后缀表达式
- shell排序
- Zookeeper Api(java)入门与应用
- PHP中利用redis实现消息队列处理高并发请求
- 位运算符及原码、反码和补码
- CSS布局模型及定位技术的应用
- 最大子数组问题-暴力求解-c++代码实现
- 数据库事务隔离级别与锁机制的实现----不是针对PostgreSQL,而是普遍的原理,来自互联网,有删节
- linux 系统 git 搭建中心仓库
- module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6问题解决