#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void Myprint(int val)
{
cout << val << " ";
}
void test01()
{
vector<int>v1;
vector<int>v2;
for (int i = 0; i < 10; i++)
{
v1.push_back(i);
v2.push_back(i + 5);
}
vector<int>vTarget;
//目标容器需要提前开辟空间
//最特殊情况 两个容器没有交集 就是两个容器size 相加
vTarget.resize(v1.size()+ v2.size());
//获取并集
vector<int>::iterator itEnd = set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), vTarget.begin());
for_each(vTarget.begin(), itEnd, Myprint);
}
int main()
{
test01();
system("pause");
return 0;
}
02_常用集合算法_set_union
最新推荐文章于 2024-04-23 19:38:27 发布