Vector is generally used as a dynamically growing array, which is quite different from array
Here is mainly a summary of adding elements and deleting elements of vector
vector iterator
The protected member of vector has 3 iterators
start-the head of the currently used space
finish-the end of the currently used space
end_of_storage-the end of the current available space
Vector uses 2 iterators start and finish to indicate the range that has been used, and end_of_storage to indicate the range of the entire space
Similar to the following figure:
Add elements
The spare space is greater than or equal to the number of new elements && The number of existing elements after the insertion point is greater than the number of new elements
The spare space is greater than or equal to the number of new elements && The number of existing elements after the insertion point is less than or equal to the number of new elements
Deleting elements is easier than inserting elements
Deleting elements is to remove this space, adjust the finish iterator, the end_of_storage iterator basically does not move, and move the element after the deletion point forward