排序之插入排序
来源:互联网 发布:淘宝交换的主板靠谱吗 编辑:程序博客网 时间:2024/05/15 08:48
<<insertion sort(A) 升序排列 伪代码 parameter:A[1..n]for j = 2 to A.length<span style="white-space:pre"></span>key = A[j]//Insert A[j] into the sorted sequence A[1..j-1]<span style="white-space:pre"></span>i = j-1<span style="white-space:pre"></span>while i>0 and A[i]>key<span style="white-space:pre"></span>A[i+1] = A[i]<span style="white-space:pre"></span>i = i-1<span style="white-space:pre"></span>A[i+1] = key<<C++//meclass Solution {public: void insertion_sort(vector<int>& A) { for(int j = 1;j<A.size();++j){<span style="white-space:pre"></span>key = A[j];<span style="white-space:pre"></span>i = j-1;<span style="white-space:pre"></span>while(i>=0&&A[i]>key){<span style="white-space:pre"></span>A[i+1] = A[i];<span style="white-space:pre"></span>--i;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>A[i+1] = key;<span style="white-space:pre"></span>} }};//internetvoid InsertionSort(int *a, int len) { for (int j=1; j<len; j++) { int key = a[j]; int i = j-1; while (i>=0 && a[i]>key) { a[i+1] = a[i]; i--; } a[i+1] = key; } }
原理比较浅显。
0 0
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- 排序之插入排序
- GetVersionEx的降级问题
- RTSP协议介绍
- android Bitmap的内存管理
- object_setInstanceVariable is unavailable: not available in automatic reference counting mode
- 将字符串表示的字母转换成对应的字符类型的变量
- 排序之插入排序
- React Tips
- 第四届 蓝桥杯 第三题 第39阶台阶 搜索 解题报告
- Mysql四种模糊查询
- Normal Mapping 法线贴图
- 解决WebBrowser显示HTML乱码问题
- Java Swing 弹出退出提示框(代码示例)
- java实现文件的复制
- 理解MySQL——索引与优化