C++ set_union
来源:互联网 发布:淘宝网店运费怎么设置 编辑:程序博客网 时间:2024/05/16 00:42
原文
set_union可以合并两个排好序的区域成一个set
i.e. 去重
it = set_union(first, first + 5, second, second + 5, v.begin());
first, second都是数组,并且排好序了
v 是 vector,把集合生成到 v里去
然后 返回生成集合末尾的迭代器 it
// set_union example#include <iostream> // std::cout#include <algorithm> // std::set_union, std::sort#include <vector> // std::vectorusing namespace std;int main () { int first[] = {5,10,15,20,25}; int second[] = {50,40,30,20,10}; vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 vector<int>::iterator it; sort(first, first + 5); // 5 10 15 20 25 sort(second, second + 5); // 10 20 30 40 50 it = set_union(first, first + 5, second, second + 5, v.begin()); // 5 10 15 20 25 30 40 50 0 0 v.resize(it - v.begin()); // 5 10 15 20 25 30 40 50 cout << "The union has " << (v.size()) << " elements:\n"; for (it = v.begin(); it != v.end(); ++it) cout << ' ' << *it; cout << '\n'; return 0;}
0 0
- set_union
- set_union
- C++:set_union is not a member of std;
- C++ set_union
- set_union set_intersection
- set_union的用法
- set_union的几个例子
- set_union,set_intersection,set_difference,set_symmetric_difference
- set_union的几个例子
- C++ set_union,set_intersection,set_difference
- set_union的几个例子
- set_union()的用法
- set中的set_union用法
- set_union的几个例子
- C++ STL set_union的用法
- STL set_difference set_intersection set_union 操作
- C++ STL merge,set_union,set_intersection,set_difference,set_symmetric_difference
- STL 之includes,set_intersection,set_union,set_difference,set_symmetric_difference
- 常量
- Tsinsen A1119 进位制表
- LCD电子书项目(六)
- init方法的重构
- tomcat部署web应用的三种方式
- C++ set_union
- Android View体系(九)自定义View
- 软妹币!软妹币!软妹币!——重大4月月赛
- 二叉堆(JAVA实现)
- RNN学习笔记(六)-GRU,LSTM 代码实现
- 文章标题
- HDU-1210Eddy's 洗牌问题
- java虚拟机学习之内存管理
- Count Primes