insertion sort
来源:互联网 发布:杭州电信网络缴费电话 编辑:程序博客网 时间:2024/05/16 14:37
MITOCW lesson 1 insertion sort
pseudocode:
INSERTION-SORT(A)1 for j ← 2 to length[A]2 do key ← A[j]3 ▹ Insert A[j] into the sorted sequence A[1 ‥ j - 1].4 i ← j - 15 while i > 0 and A[i] > key6 do A[i + 1] ← A[i]7 i ← i - 18 A[i + 1] ← keyReference: Introduction to Algorithm
#include <iostream>using namespace std;int main(){ int j=0; int a[]= {2,51,23,45,65,234,67,1,24,56,43,42}; int num=sizeof(a)/sizeof(j); cout <<num<<endl; int key=0; int mid=0; for(j=1; j<num; j++) { key=a[j]; for(int k=j-1; k>=0; k--) { if(key<a[k]) { a[k+1]=a[k]; a[k]=key; //每次排序后的结果 for(mid=0; mid<num; mid++) { cout<<a[mid]<<" "; } cout<<endl; } else { break; } } } for(j=0; j<num; j++) { cout<<a[j ]<<" "; } return 0;}
- Insertion Sort
- Insertion Sort
- insertion sort
- insertion sort
- Insertion Sort
- insertion sort
- insertion sort
- insertion sort
- insertion sort
- Insertion Sort
- Insertion Sort
- Insertion-sort
- Insertion sort
- Insertion sort
- insertion sort
- Insertion sort
- Insertion sort
- Insertion Sort
- 根据tablename取得对应的所有数据
- 统计ip的发送频率和该ip发送的有效消息(去除相似消息)的数目
- Android 实时获取麦克风输入音量的代码
- 使用管理员权限运行AutoHotkey的Script
- mysql 导入导出数据说明
- insertion sort
- 函数传参(指针)问题
- struts2文件下载 注意中文问题
- 2013-6-8日记
- JavaScript:作为方法的函数
- 很蛋碎,都不知道在干什么。。。快疯了。。。。
- mysql 创建用户 授予权限
- python 遍历修改工程下所有CVS/Root文件
- 整理过后的电驴emlue的源码,直接用vs2010编译可运行,不需要配置环境