Hi, I am Trying to create a vector of vectors
I have managed to create the vector structure
but now i need to add elements to it with a particular sequence
for example if i call the function, with a variable number (which = 5)
i want the vector to be able to go through and create a vector structure like
vector vector 0 = 1, 0, 0, 0, 0, 0
vector vector 1 = 2, 0, 0, 0, 0, 0
vector vector 2 = 3, 0, 0, 0, 0, 0
vector vector 3 = 4, 0, 0, 0, 0, 0
vector vector 4 = 5, 0, 0, 0, 0, 0
i have tried many ways but cannot seem to assign the correct values
This dosnt work and just assigns 0 to all elements,Code:vector<vector<int> > MYVEC; // create vector
void Initialise(vector<vector<int> > &MYVEC, int num) // function to initialise vector
{
int v = 1; // used to assign 1, 2, 3 ...
int k = 0; // used always assigning 0 to other elements
for ( int i = 0; i < num; i++ )
{
MYVEC.push_back ( vector<int>() );
MYVEC[i].push_back(i);
for ( int j = 0; j < numVertices; j++ )
{
MYVEC[i].push_back(i);
MYVEC[i][j] = 0;
}
}
}
so is like:
vector vector 0 = 0, 0, 0, 0, 0, 0
vector vector 1 = 0, 0, 0, 0, 0, 0
vector vector 2 = 0, 0, 0, 0, 0, 0
vector vector 3 = 0, 0, 0, 0, 0, 0
vector vector 4 = 0, 0, 0, 0, 0, 0
i need the first element of each vector in the big vector to be go up from 1, 2 ... etc
Thanks