我的功能search_intersection
收到一套<set<string> >& inter_section
。
我想得到所有子集的交集inter_section
。
例如,如果:
inter_section = { { lion, cat } , {lion, bird}, {lion, cat, bird} }
我想:
result = { lion }
此刻我这样做了
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;
}
非常感谢!