The member function insert(p, t)
has the same effect on both list
and vector
containers, but the cost is different. Inserting an element into list
is cheap, while inserting an element into vector
will cause all the elements after the newly inserted element be moved. Thus every time the while
loop body is excuted, all elements in the vector
are moved backward, and new element is inserted in the front of the vector
.