Sequential containers:
Sequential containers include: vector, deque, list, forward_list, array, and string
vector: A variable-size array that holds elements in a contiguous memory space. Supports fast random access. Inserting a delete element at a location other than the tail may be slow.
PS: When the element is already filled with pre-allocated memory space, when inserting new elements, a new memory space is created, twice times the size of the previous vector, and the elements inside the vector are copied into the new memory space.
The insertion and deletion of vectors causes the invalidation of iterators
List : Doubly linked list. Only bidirectional sequential access is supported. Inserting and deleting any position in the list is quick.
Note Several functions:
Splice a contiguous data of 1 lists before a location in another list
Merge, sort (using a quick row)
deque: bidirectional queue, The continuous space of the double-ended openings (which logically appears to be, but not the linear continuous space of vectors). Inserting deleted data at the tail and at the beginning is quick.
the difference between deque and vector :
1.deque allows the insertion or deletion of data at the head end in constant time.
2.deque does not have a so-called capacity concept, because it is dynamically combined with segmented contiguous space, and can be added to a new space at any time and linked together.
The implementation principle of deque:
Deque actually consists of a section of quantitative continuous spatial links, once it is necessary to add new space in the head or tail of the deque, a quantitative continuous space is configured, threaded to the head end or end of the entire deque.
Therefore deque must have a central control component to maintain the illusion of the whole continuum and provide a random access interface.
Deque uses a small contiguous space called the so-called "map", each element in "map" is a pointer to another large contiguous memory space, called a buffer, and the buffer is both the body of the deque storage space.
How to maintain the illusion of "overall continuity"?
It is implemented by overloading the operator++ and operator--of Deque iterators.
From the source you can see that there are so few members in the Deque iterator class
t* cur; The current element in the buffer referred to by this iterator
t* first; The header in the buffer referred to by this iterator
T* last; The tail in the buffer referred to by this iterator
Map_point node; Point to the corresponding element in "map"
Stack
Stack is based on deque or list as the bottom structure, and its interface is changed to conform to the "advanced after-out" feature to achieve. Strictly speaking, STL container is not a class, STL called this container adapter.
Ps:stack No iterators
Queue
Queue is the same as stack.
Sequential containers also have
Forward_list Unidirectional linked list
A container similar to a vector, designed to hold characters.
"C + +" STL container Summary (i) sequential container