开发者

Mathematical set library/header

In what library/header (if any) is mathematical set defined? I need set to have fun开发者_JAVA百科ctions like intersection, union etc.


You can use std::set (<set>) for the set and std::set_intersection and std::set_union (<algorithm>) for this.


Use <set> and <algorithm>.

Then the std provides std::set_union, std::set_intersection and so on.

example:

#include <set>
#include <algorithm>

 ...
std::set<int> s1, s2;
for(int i = 0; i < 20; ++i)  s1.insert(i);
for(int i = 10; i < 30; ++i) s2.insert(i);
std::set<int> my_union, my_intersection;
std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(my_union, my_union.begin()));
std::set_interesction(s1.begin(), s1.end(), s2.begin(), s2.end(), std::inserter(my_intersection, my_intersection.begin()));


You can use std::set. You can use algorithms such as set_intersection on it.


Search <algorithm> header for functions

· set_difference
· set_intersection
· set_symmetric_difference
· set_union


Write the following on top of your code

#include <set>
#include <algorithm>


You can try https://github.com/aseprano/Set, it provides the things you are looking for. Do not use std::set or any other stl container in that they does not have full support to math sets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜