简单插入排序(C++版)
2016-02-21 21:49
309 查看
#include <iostream> using namespace std; /** \ Insert Sort * * Key: * * reserve: tm = a[i] * * position: int j = i-1 * * move : while * */ template <typename T> void insertSort(T a[], int n) { T tm; for (int i = 1; i < n; i++) { tm = a[i]; int j = i-1; while (a[j] > tm && j >= 0){ a[j+1] = a[j]; j--; } a[j+1]=tm; } }
相关文章推荐
- 适配器模式
- 《C++Primer》 学习——第三章
- C++、C#写的WebService相互调用
- c++primer阅读笔记之数组与指针
- c++ 写注册表 并将exe添加到开机启动
- C++Primer charpter1.
- Dev-C++ 小问题锦集
- Klib - C语言通用库
- iOS 学习第十八天 OC语言 NSArray的使用
- ios 学习第十七天 OC语言 Protocol基本使用
- iOS 学习第十六天 OC语言 autorelease基本使用
- C/C++开源项目清单
- IOS学习第十五天 OC语言 内存管理简介
- iOS 学习第十四天 OC语言 OC中的私有方法
- C++中搜索、截取字符串
- c++ 读注册表信息 读取CPU信息
- C++面向对象编程<一>:简介
- 《c++primer》学习随笔——预处理器变量
- Effective C++学习记录
- Effective C++学习记录