Hi all
I have a2d vector say
vector<vector<int> > V ( 5,vector<int>(5)); // 25 size
Suppose i want to do this operation. if the last element in vector[i] and the first element of v[i+1] differ by a value greater than 20..., i want to push the v[i+1].front() element into v[i].back() position in the array.
how to do it?
i wrote a code like this but got segmentation error. please help me how to design this one!!
i know there is a flaw but the logic iw ant to achieve is simple. please suggest how it shud be rewrote.Code:int main (void)
{
vector <vector<int> > v (5,vector<int>(5));
vector<int>::iterator it;
int rnd;
for (int i=0;i<5;i++)
{
for ( int j=0;j<5;j++)
{
rnd = rand() % 100;
v[i][j]= rnd;
//cout<<v[i][j]<<" ";
}
}
for (int i=0;i<5;i++)
{
if ( ( (v[i].back() )-(v[i+1].front() ) ) >= 20)
{
//cout<<"ok!"<<endl;
v[i].push_back(v[i+1].front());
v[i].resize(v[i].size()+1);
v[i+1].resize(v[i+1].size()-1);
}
}
return 0;
}