如果我知道一个集合是另一个集合的子集,并且我想找出差异,那么最有效的方法是什么?
前任。
伪代码
> set<int> set1 = {1 2 3 4 5 6 7 8 9 10}
> set<int> set2 = {5 6 7}
我想减去set2
from set1
:
这里的答案是
{1 2 3 4 8 9 10}
Use std::set_difference
在发现<algorithm>
:
#include <algorithm>
#include <set>
#include <iterator>
// ...
std::set<int> s1, s2;
// Fill in s1 and s2 with values
std::set<int> result;
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
std::inserter(result, result.end()));
片段来源 https://stackoverflow.com/questions/283977/c-stl-set-difference
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)