您的位置:首页 > 编程语言 > C语言/C++

简单插入排序(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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: