I have two sets:
std::set<int> one;
std::set<int> two;
Each set contains indices of some objects - I need to deactivate the indices only in one, and activate the indices only in two. The indices that are in both will remain as is.
If these were sorted vectors, I would do something like:
int c1 = 0; int c2 = 0;
while(true){
if(one[c1] < two[c2]){
one[c1].deactivate();
c1++;
}else if(one[c1]==two[c2]){
c1++; c2++;
}else{
two[c2].activate();
c2++;
}
if(c1 == one.size() || c2 == two.size()){
break;
}
}
while(c1<one.size()){
one[c1].deactivate();
c1++;
}
while(c2<two.size()){
two[c2].activate();
c2++;
}
Example:
one = {1,3,5,6,7,8,10}
two = {2,4,6,8,10,12}
Before running the algorithm:
Active: 1,3,5,6,7,8,20
After running the algorithm:
Active: 2,4,6,8,10,12
But as these are sets, I'm not sure how to iterate over them this way. How do I accomplish the same thing ?