I have a vector that contains Points on a board
and I would like to do the following:
1) if a Point appears an even number of times i would like to delete all of the same Points.
2) if a Point appears an odd number of times i would like to leave only the last appearance.
here is my code, which makes an windows error while running. tried debugging but seems like its inside the vector file.
vector<Point>::iterator i=_shapeOutline.begin();
int counter=1;
for (;i!=_shapeOutline.end();i++){
vector<Point>::iterator j=i;
j++;
for(;j!=_shapeOutline.end();j++){
if ((*i)==(*j))
counter++;
}
bool saveOne= counter%2==0;
if (counter!=1){
Point t=(*i);
for(vector<Point>::iterator j=_shapeOutline.begin();
j!=_shapeOutline.end();j++)
if (t==(*j)){
if(saveOne)
_shapeOutline.erase(j);
else{
if (counter==1)
break;
_shapeOutline.erase(j);
counter--;
}
}
}
cout<<counter<<" "<< (*i).getX()<<" "<<(*i).getY()<<endl;
counter=1;
}
any idea whats the problem?
thanks!
is there a problem erasing while iterating? ive seen a few posts saying it might be a problem?
if i cant use iterator whats a good way to erase the way i need without sorting the vector?
need to keep it in the same order
thanks