- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章c++ STL set_difference set_intersection set_union 操作由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
以下是STL algorithm的几个函数,使用的条件是有序容器,所以 vector在被sort了之后是可以使用的,set也是可以使用的.
set_difference 这个是求得在第一个容器中有,第二个容器中没有的。set_intersection 求两个容器的交, set_union 求两个容器的并.
set_symmetric_difference 求两个容器的差.
最后使用的时候注意要提前分配好最后的盛放容器,其大小最好是两个操作容器的和,然后需要根据返回的迭代器resize一下,看下面的例子.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
// set_symmetric_difference example
#include <iostream> // std::cout
#include <algorithm> // std::set_symmetric_difference, std::sort
#include <vector> // std::vector
int
main () {
int
first[] = {5,10,15,20,25};
int
second[] = {50,40,30,20,10};
std::vector<
int
> v(10);
// 0 0 0 0 0 0 0 0 0 0
std::vector<
int
>::iterator it;
std::sort (first,first+5);
// 5 10 15 20 25
std::sort (second,second+5);
// 10 20 30 40 50
it=std::set_symmetric_difference (first, first+5, second, second+5, v.begin());
// 5 15 25 30 40 50 0 0 0 0
v.resize(it-v.begin());
// 5 15 25 30 40 50
std::cout <<
"The symmetric difference has "
<< (v.size()) <<
" elements:\n"
;
for
(it=v.begin(); it!=v.end(); ++it)
std::cout <<
' '
<< *it;
std::cout <<
'\n'
;
return
0;
}
|
最后此篇关于c++ STL set_difference set_intersection set_union 操作的文章就讲到这里了,如果你想了解更多关于c++ STL set_difference set_intersection set_union 操作的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我认为此处描述的 set_intersection STL 函数:http://www.cplusplus.com/reference/algorithm/set_intersection/在数学意义
使用 中的功能时, 通常有一个额外的参数来自定义比较。但是我不太明白关于参数的描述(Documentation of set_intersection)。 Binary function that
有什么方法可以对两种不同类型的集合执行 std::set_intersection 吗? 我有两套: std::set l_set1; std::set l_set2; 我可以为它们定义一些比较器来检
这个问题在这里已经有了答案: std::back_inserter for a std::set? (2 个答案) 关闭 2 年前。 是否可以将 std::set_intersection 或其他
我正在编写一个代码,根据对象的 ID 将两个对象 vector 相交。我收到运行时错误。我试图找出问题所在,但不知道为什么?你能帮我吗? #include #include #include u
struct Cord { int x_cord; int y_cord; Cord(int x = 0,int y = 0):x_cord(x
我想找到两张 map 之间的交点。我的 map 有结构 map , 其中line是一个结构。问题是当我使用 set_intersection为了执行交集,我得到了图像中表示的以下错误。 下面是我的代码
我需要获取两个 vector 之间的交集列表。在我的例子中, vector 是用户类型的 vector 。所以为了获得封装的数字,我必须使用比较器函数。 我还希望能够获得与偏移量的交集。例如,给定两个
我正在阅读有关 set_intersection 的内容,它似乎期望用户提前分配正确数量的空间(或更多),但这不是很奇怪吗?在 C++ 中,您经常使用 std::vector 动态分配空间。为什么 s
std::set m{1,2, 4}; std::set n{2,3, 4}; std::set mn; std::set::iterator it; it=set_intersection(m.be
This question建议使用 std::set_intersection 来查找两个数组的交集。使用 std::find 不是同样有效吗? int a[5] = {1, 2, 3, 4, 5};
我有一个类有两个属性: set ens1_; set ens2_; 现在,我有一个方法可以找到这两个集合之间的交集。这是我在我的方法中写的: set ens; set::iterator it;
我想知道如何 thrust::set_intersection有效,但从我的测试结果来看,我对这个函数的作用更加困惑。 举几个例子: const int size1 = 5; const int si
我有一个简单的要求,我需要从另一个 vector 中的字符串主列表中找到一个 vector 中字符串的出现。一开始我可以很容易地做到这一点: vector custom_list; set maste
我在尝试理解使用自定义比较器时 std::set_intersection 的语法。我正在尝试获取集合 one 和 two 的交集,这将导致集合 (intersect) 仅包含元素 f2. 我得到错误
我知道这些命令适用于两组。 是否有任何简单快速的方法可以为超过两组的情况执行此操作。 我想我可以为此使用某种循环,但也许有更好的方法。 谢谢 最佳答案 对于集合并集,如果要查看 M 个集合中哪个集合的
大家好:)我想创建一个个人集合类并重载运算符/=,就我的类而言,该运算符应该用于获取两个集合的插值。我收到以下错误: 错误:分配只读位置 '__result.std::_Rb_tree_const_i
下面代码的复杂度是多少? set S1, S2, ans; set_intersection(S1.begin(), S1.end(), S2.begin(), S2.end(), inserter(
我想知道标准库中是否有任何工具可以同时计算两个排序范围之间的交集和差集。带有以下签名的东西: template Output3 decompose_sets (Input1 first1, Inpu
std::set_intersection允许我通过将元素输出到 输出迭代器 来检索两个 std::set 实例之间的所有共同元素。在我的特定情况下,我只对检查两个集合是否有任何共同元素感兴趣。 我目
我是一名优秀的程序员,十分优秀!