c++: vector of vector issue
pI wrote a c++ code where i'm testing the running time of vector
push_back. I have a vector of vector. I called my main vector, mainVec,
and embedded vector, subVec. So, I push backed 2^20 elements into subVec
and then push backed subVec 2^20 times into mainVec. However, in the loop
of subVec-push_back I have a cout command which doesn't get executed. I
was hoping you can point out my mistake. /p pHere is the code (There is no
error in the code, though):/p precodevectorlt;intgt; subVec; vectorlt;
vectorlt;intgt; gt; mainVec; //Fills the subvector with 2^20 elements for(
size_t i = 0; i lt; (pow(2,20)+1); ++i) subVec.push_back(i); //Filling of
the maiVec with 2^20 subVec for( size_t j = 10; j lt; 21; ++j) { cout
lt;lt; pow(2,j) lt;lt; endl; clock_t t1 = clock(); //2^j times subVec is
push_backed for j lt; 21 for( size_t k = 0; k lt; pow(2,j); ++k )
mainVec.push_back( subVec ); t1 = clock()-t1; //Outputting to file cout
lt;lt; \t lt;lt; (float(t1) / CLOCKS_PER_SEC) lt;lt; endl; //ofs lt;lt;
pow(2,j) lt;lt; \t\t lt;lt; (float(t1) / CLOCKS_PER_SEC) lt;lt; endl; }
/code/pre
No comments:
Post a Comment