Could someone help me to write a logic that converts a ID array to a 2D vector.
something like
int array[] = {1, 4, 5, 7, 9, 3}; // dynamic array
vector <vector int> ex;
How can I now place the values in ex from array.. so that it forms 2 vectors each of 3 values?
I have searched for help with no use and have tried it myself as below:
for(int i=0; i<2; i++)
{
rowTemp_ex.assign(array, array+3));
ex.push_back(rowTemp_ex);
rowTemp_ex.erase(rowTemp_ex.begin() , rowTemp_ex.end());
}
First, compute how many row-vectors there will be. If each one has three elements, the total is the size of the array divided by 3.
Now create a vector with that number of row-vectors with three elements each:
And then go through the original array and fill up each cell of the result, using integer division and remainder operations: