标签:
1、
http://bbs.csdn.net/topics/370029802
1 #include <iostream> 2 #include <limits> 3 #include <assert.h> 4 #include <vector> 5 #include <algorithm> 6 #include <functional> // For greater<int>( ) 7 8 9 using namespace std; 10 11 12 int _tmain(int argc, _TCHAR* argv[]) 13 { 14 std::vector<int> vRqt; 15 std::vector<int> vRsp; 16 std::vector<int> vAll; 17 //vAll.reserve(100); 18 vRqt.push_back(11); 19 vRqt.push_back(2); 20 vRqt.push_back(3); 21 vRqt.push_back(22); 22 sort(vRqt.begin(),vRqt.end()); 23 vRsp.push_back(31); 24 vRsp.push_back(1); 25 vRsp.push_back(4); 26 vRsp.push_back(11); 27 vRsp.push_back(3); 28 sort(vRsp.begin(),vRsp.end()); 29 merge(vRqt.begin(),vRqt.end(), vRsp.begin(),vRsp.end(), back_inserter(vAll)); //合并 30 sort(vAll.begin(),vAll.end());//排序 31 vAll.erase( unique( vAll.begin(), vAll.end() ), vAll.end());//擦出 32 copy(vAll.begin(),vAll.end(),ostream_iterator<int>(cout," "));//显示 33 return 0; 34 }
ZC:注意 第29行 back_inserter() 和 第31行 unique() 的使用
2、
标签:
原文地址:http://www.cnblogs.com/cppskill/p/5256896.html