How do I check for the empty intersection of two std::set
s? I can use set_intersection
, but that's unnecessarily slow, I need only bool
answer.
Remark: std::set
means ordered sets, they are of the same type etc.
Anything wrong with just coding it yourself?
bool empty_intersection(const set<int>& x, const set<int>& y)
{
std<int>::const_iterator i = x.begin();
std<int>::const_iterator j = y.begin();
while (i != x.end() && j != y.end())
{
if (*i == *j)
return false;
else if (*i < *j)
++i;
else
++j;
}
return true;
}
Something like that anyway. Completely untested code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With