注意:
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
class p {
public:
void operator()(int val)
{
cout << val << " ";
}
};
void test01()
{
vector<int> v1 = { 1,2,3,4,5,6 };
vector<int> v2 = { 4, 5, 6, 7, 8, 9, 10, 11, 12 };
vector<int> v3;
//min是标准算法头文件里面的一个函数
//最特殊情况,两个容器没有交集,并集就是两个容器size相加
v3.resize(v1.size()+ v2.size());
//返回的是v3容器最后一个迭代器地址
vector<int>::iterator v3end=set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), v3.begin());
cout << "打印v3容器全部元素:";
for_each(v3.begin(), v3.end(), p());
cout << endl;
cout << "只打印并集部分:";
for_each(v3.begin(), v3end,p());
}
int main()
{
test01();
system("pause");
return 0;
}
自定义函数类型:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有