I
I
igoodmood2016-09-19 20:32:19
Programming
igoodmood, 2016-09-19 20:32:19

How to merge two non-sets correctly?

Hello! When studying sets, the question arose: How to correctly combine two non-sets of this type (namely, the left side)? d125afa8ce8144158b16b3b1b855b73e.PNG
I know how to implement the intersection of the right side:

set<int> inter_no_AB;
  set_intersection(begin(universum_diff_A), end(universum_diff_A),
    begin(universum_diff_B), end(universum_diff_B),
    inserter(inter_no_AB, begin(inter_no_AB)));

But at the expense of the left there are difficulties. I tried to do it by analogy, but it didn’t work:
set<int> diff_union;
  set_union(begin(universum_diff_A), end(universum_diff_A),
    begin(universum_diff_B), end(universum_diff_B),
    inserter(diff_union, begin(diff_union)));

This piece of code does not work correctly.
Therefore, I ask for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2016-09-20
@fshp

If the initial sets are given, then something like this:

set<int> A_union_B;
set<int> diff_union;
  set_union(begin(A), end(A),
    begin(B), end(B),
    inserter(A_union_B, begin(A_union_B)));
  set_difference(begin(universum), end(universum),
    begin(A_union_B), end(A_union_B),
    inserter(diff_union, begin(diff_union)));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question