Nevermind, I wrote a small function and it does it for me!
1 2 3 4 5 6 7 8 9 10 11 12 13
void Change2DVectorSize(vector< vector<double> > &a, int nRows,int nColumns)
{
int i;
vector<double> CurrRow;
a.clear();
for(i=0;i<nColumns;i++)
CurrRow.push_back(0.0);
for(i=0;i<nRows;i++)
a.push_back(CurrRow);
}
It would have been nice if such a function was inbuilt in C++. Btw, can somebody help me change the above code from 'double' to 'template'? So that I can reuse it for other datatypes.. int etc. Let me give it a try:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14
template < typename T >
void Change2DVectorSize(vector< vector<T> > &a, int nRows,int nColumns)
{
int i;
vector<T> CurrRow;
a.clear();
for(i=0;i<nColumns;i++)
CurrRow.push_back((T)0);
for(i=0;i<nRows;i++)
a.push_back(CurrRow);
}