C++ 希尔排序
来源:互联网 发布:派尔高网络摄像机价格 编辑:程序博客网 时间:2024/06/14 16:38
基本思想:
将整个待排序记录分割成若干个子序列,在子序列内分别进行直接插入排序,待整个序列中的记录基本有序时,对全体记录进行直接插入排序。
子序列不是被简单的“逐段分割”,而是将相距某个“增量”的记录组成一个子序列,希尔排序开始时增量较大,每个子序列中的记录个数较少,从而排序速度较快;当增量较小时,虽然每个子序列中记录个数较多,但整个序列已基本有序,排序速度也较快。
#include <iostream>using namespace std;void shellSort(int arr_int[], int n){ int j,step; for(step = n/2; step>0; step = step/2) { for(int i=step+1; i<=n; i++) { j = i - step; if(j>0 && arr_int[i]<arr_int[j]) { arr_int[0] = arr_int[i]; arr_int[i] = arr_int[j]; arr_int[j] = arr_int[0]; } } }}int main(){ int arr_int[] = {0,6,78,20,15,3,7,69,21}; int n = sizeof(arr_int)/sizeof(arr_int[0]) - 1; shellSort(arr_int,n); for(int i=1; i<=n; i++) { cout<<arr_int[i]<<" "; } return 0;}
- 希尔排序C语言
- c语言希尔排序
- C++,希尔排序
- 希尔排序(c++)
- c++ 希尔排序
- 希尔排序(C语言版)
- C语言希尔排序
- 希尔排序c语言版
- 希尔排序 C语言版
- C语言------希尔排序
- C希尔排序
- C 插入排序 希尔排序
- 希尔排序(C语言)
- C语言希尔排序了解
- 希尔排序C语言代码
- C语言实现希尔排序
- 希尔排序(C语言版)
- 算法 - 希尔排序(C)
- js 模拟qq对话框的拖动效果
- errorORA-28001 the password has expired .或者Caused by: java.sql.SQLException: ORA-28001: 口令已经失效
- Zigbee基础实验之ADC
- 苹果的傲慢
- 电信项目三月结
- C++ 希尔排序
- 线程与内核对象的同步
- 简易任务调度实现--可用于windows服务/asp.net网站执行后台计算
- php调用C++扩展库出现段错误 (core dumped)
- [QTP] Retrieves the value of the cell in the specified row of the parameter in the run-time Data Tab
- json格式的传输问题
- 插入拔掉耳机流程 audio headset
- vc 命令行下运行
- JavaScript常见的编码陷阱