Saturday, 28 September 2013

Vector of vectors , Separating different values from array

Vector of vectors , Separating different values from array

I need to separate values from an 2d array. All i need to do is to store
all indexes of fields with certain values.
For example i may have an array which has 3 cells with value 1 and 10
fields with value 2. I tried to create 1 vector which stores all indexes
for value 1 and the other one that stores all indexes for value 2 .
here's a code I've been trying to write , but it doesnt seem to wrok
void searchForGrains(Cell **tab, int _size){
storage.push_back(tab[0][0]);
Point p(0,0); // Point refers to array indexes
storage[0].points.push_back(p);
for(int i=0 ; i<_size ; ++i){
for(int j=0 ; j<_size ; ++j){
int counter = 0;
for(unsigned int k=0 ; k<storage.size() ; k++){
if(tab[i][j].value == storage[k].value){
Point pp(i,j);
storage[k].points.push_back(pp);
}
else
counter++;
}
if(counter == storage.size())
storage.push_back(tab[i][j]);
}
}
}

No comments:

Post a Comment