vectors

I have a 2d vector.I have inserted its initial pairs.Now I want to insert any transitive pair in the original vector.Using c++ vector when I try to insert second time after comparing pairs they are not getting inserted.I am using push_back function.Please help.

t=0;

for(i=0;i<k;i++){
for(j=1;j<k;j++){
if(a[i][t+1]==a[j][t]){
//a.resize(1);

vector<int> temp;
temp.push_back(a[i][t]);
temp.push_back(a[j][t+1]);

a.push_back(temp);

}


}
}
your post is unclear - is the 2d vector a vector of std::pair<int, int>?
no ,i have declared it as

vector< vector<int> > a;

vector<int> temp;


temp.push_back(x);
temp.push_back(y);


a.push_back(temp);
Last edited on
> they are not getting inserted
¿how did you check that?

> a[i][t+1]==a[j][t]
¿what's `t'? ¿what value apart of 0 may it hold? ¿does that condition holds true at least one time?

1
2
for(i=0;i<k;i++){
   for(j=1;j<k;j++)
think carefully, ¿why does `j' start at 1?
also, you should limit their scope.


provide a testcase that does reproduce your issue.
Topic archived. No new replies allowed.