My function search_intersection receive a set <set<string> >& inter_section.
I want get the intersection over all subsets in inter_section.
For example if:
inter_section = { { lion, cat } , {lion, bird}, {lion, cat, bird} }
I want:
result = { lion }
At the moment I did this
set<string> search_intersection(set <set<string> >& inter_section)
{
set <set<string> >::iterator iter_ss;
set <string> result;
for (iter_ss = inter_section.begin(); iter_ss != inter_section.end(); ++iter_ss)
{
set_intersection(iter_ss.begin(),iter_ss.end(),
result.begin(),result.end(),
std::inserter(result.begin(),result.end()));
}
cout << endl;
return result;
}
Thanks a lot!
Let’s try again: (Uncompiled code)
Note that the call to set_intersection passes the begin/end of the set pointed to by the iterator. Also, there are at least two places where
constshould be applied to this code.You can’t write the results of
set_intersectioninto one of the inputs, either. Hence a temp variable.