Check out example codes for "c++ vector insert time complexity". It will help you in understanding the concepts better.

Code Example 1

// inserting into a vector #include <iostream> #include <vector>  int main () {   std::vector<int> myvector (3,100);   std::vector<int>::iterator it;    it = myvector.begin();   it = myvector.insert ( it , 200 );    myvector.insert (it,2,300);    // "it" no longer valid, get a new one:   it = myvector.begin();    std::vector<int> anothervector (2,400);   myvector.insert (it+2,anothervector.begin(),anothervector.end());    int myarray [] = { 501,502,503 };   myvector.insert (myvector.begin(), myarray, myarray+3);    std::cout << "myvector contains:";   for (it=myvector.begin(); it<myvector.end(); it++)     std::cout << ' ' << *it;   std::cout << '\n';    return 0; }</textarea>          <div class="answer_source">Source: <a target="_blank" href="http://www.cplusplus.com/reference/vector/vector/insert/">www.cplusplus.com</a></div>         <br/>

Learn ReactJs, React Native from akashmittal.com