previous | start | next

## Removing and Inserting Elements

- To insert an insert an element in the middle of a vector, you must add a new element at the end of the vector and move all elements above the insertion location up by one slot.

  >     void insert(vector<string>& v int pos, string s)
  >     {
  >        int last = v.size() - 1;
  >        v.push_back(v[last]);
  >        for (int i = last; i > pos; i--)
  >           v[i] = v[i - 1];
  >        v[pos] = s;
  >     }

- Note that when you insert an element you start at the end of the vector, move that element up, then go to the one before that.

previous | start | next