Set theory operations in C++ using STL


Set operation in STL

1. Is set A subset of set B
if(includes(vecB.begin(),vecB.end(),vecA.begin(),vecA.end(),compareFunc))
cout<<"VecA is subset of VecB";

2. The union of A and B
insert_iterator<set<int> > insertiter(resultset, resultset.begin());
set_union(first.begin(), first.end(), second.begin(),second.end(), insertiter);

3. The intersection of A and B
set_intersection(first.begin(), first.end(), second.begin(),second.end(), insertiter);

4. The difference of A and B A\B
set_difference(first.begin(), first.end(), second.begin(),second.end(), insertiter);

5. The symmetric difference of A and B
set_symmetric_difference(first.begin(), first.end(), second.begin(),second.end(), insertiter);

bit operation and set theory in C++

Set union A | B Set intersection A & B Set subtraction A & ~B Set negation ALL_BITS ^ A Set bit A |= 1 << bit Clear bit A &= ~(1 << bit) Test bit (A & 1 << bit) != 0 shift operations on negative values are undefined xor using logical operators (p || q) && !(p && q)

No comments:

Post a Comment

would you like it. :)