Here is my question, I have a vector of double and I need eliminate some of them under a certain condition. Here is a code example:
vector <double> appo;
for(int i=0;i<appo.size();i++){
for(int j=i+1;j<appo.size();j++){
if( condition(appo[i],appo[j]) ){
appo.erase(appo.begin()+j);
j--;
}
}
}
Since after the erase() my size decrease by 1 and all the elements got left shifted by left, is correct to decrease j?
Ok I decide to don't use the removeif because it's a small program and I don't care right now about performance, but I got segmentation fault. Here is the code:
vector <double> *point;
for(int i=0;i<point->size();i+=3){
for(int j=i+3;j<point->size();j+=3){
if(distance((*point)[i],(*point)[i+1],(*point)[i+2],(*point)[j],(*point)[j+1],(*point)[j+2]) < treshold){
point->erase(point->begin()+j,point->begin()+j*3);
j-=3;
}
}
}
point is a vector of coordinates so something like (x1,y1,z1,x2,y2,z3,...,xn,yn,zn). Any idea?