标签:http ble name argv 插入 std i++ int log
最简单的排序算法了,每一次j--到对应的值,不会减到0,这个纠结我好久
1 #include "stdafx.h" 2 #include <iostream> 3 #include <vector> 4 using namespace std; 5 6 template <typename Comparable> 7 void insertionSort(vector<Comparable> & a) 8 { 9 int j; 10 for(int p=1 ; p<a.size() ; p++) 11 { 12 Comparable tmp = a[p]; 13 for(j=p ; j>0 && tmp<a[j-1] ; j--) 14 a[j] = a[j-1]; 15 a[j] = tmp; 16 } 17 } 18 int _tmain(int argc, _TCHAR* argv[]) 19 { 20 vector<int> ivec; 21 ivec.push_back(34); 22 ivec.push_back(8); 23 ivec.push_back(64); 24 ivec.push_back(51); 25 ivec.push_back(32); 26 ivec.push_back(21); 27 insertionSort(ivec); 28 for(int i=0 ; i<ivec.size() ; i++) 29 cout<<ivec[i]<<endl; 30 return 0; 31 }
执行结果:
标签:http ble name argv 插入 std i++ int log
原文地址:http://www.cnblogs.com/luozhijun/p/6880443.html