STL containers can be divided into the following categories:
I. Sequence containers, including vector, list, deque, String.
2. Associated containers: Set, Multiset, MAP, mulmap, hash_set, hash_map, hash_multiset, and hash_multimap
3. Miscellaneous: Stack, queue, valarray, and bitset
Implementation of each STL container:
(1) vector
Internal data structure: array.
Each element is randomly accessed. The time required is a constant.
The time required to add or delete an element at the end is irrelevant to the number of elements. The time required to add or delete an element at the beginning or in the middle changes linearly with the number of elements.
You can dynamically add or remove elements and manage the memory automatically. However, you can use the reserve () member function to manage the memory.
The iterator of the vector will become invalid when the memory is re-allocated (the elements it points to are no longer the same before and after the operation ). When more than capacity ()-size () elements are inserted into the vector, the memory will be re-allocated and all iterators will become invalid; otherwise, the iterator pointing to any element after the current element fails. When an element is deleted, the iterator pointing to any element after the element is deleted becomes invalid.
(2) deque
Internal data structure: array.
Each element is randomly accessed. The time required is a constant.
The time required to add an element at the beginning and end is irrelevant to the number of elements. The time required to add or delete an element in the middle changes linearly with the number of elements.
Elements can be dynamically added or removed, and memory management is completed automatically. member functions used for memory management are not provided.
Adding any element will invalidate the deque iterator. Deleting an element in the middle of deque will invalidate the iterator. When a deque header or tail deletes an element, only the iterator pointing to the element fails.
(3) List
Internal data structure: Bidirectional Ring linked list.
You cannot randomly access an element.
Bidirectional traversal is supported.
The time required to add or delete an element at the beginning, end, or in the middle is constant.
You can dynamically add or remove elements and manage the memory automatically.
Adding any element will not invalidate the iterator. When an element is deleted, other iterators will not expire except the iterator pointing to the currently deleted element.
(4) slist
Internal data structure: one-way linked list.
It cannot be traversed in two directions. It can only be traversed from front to back.
Other features are similar to list.
(5) Stack
Adapter, which can convert any type of sequence container into a stack. Generally, deque is used as the supported sequence container.
The element can only be post-in, first-out (LIFO ).
The entire stack cannot be traversed.
(6) queue
It can convert any type of sequence container into a queue. Generally, deque is used as the supported sequence container.
The element can only be FIFO ).
The entire queue cannot be traversed.
(7) priority_queue
It can convert any type of sequence container into a priority queue. Generally, vector is used as the underlying storage mode.
Only the first element can be accessed, and the whole priority_queue cannot be traversed.
The first element is always the element with the highest priority.
(8) Set
The keys and values are equal.
The key is unique.
Elements are arranged in ascending order by default.
If the element to which the iterator points is deleted, the iterator becomes invalid. Any other operations to add or delete elements will not invalidate the iterator.
(9) Multiset
The key may not be unique.
Other features are the same as those of set.
(10) hash_set
Compared with set, the elements in it are not necessarily sorted, but allocated by the hash function used. It can provide faster search speed (of course, related to the hash function ).
Other features are the same as those of set.
(11) hash_multiset
The key may not be unique.
Other features are the same as hash_set.
(12) Map
The key is unique.
The elements are sorted in ascending order by default.
If the element to which the iterator points is deleted, the iterator becomes invalid. Any other operations to add or delete elements will not invalidate the iterator.
(13) multimap
The key may not be unique.
Other features are the same as those of map.
(14) hash_map
Compared with map, the elements in it are not necessarily sorted by key values, but are allocated according to the hash function used, it provides a faster search speed (of course, also related to the hash function ).
Other features are the same as those of map.
(15) hash_multimap
The key may not be unique.
Other features are the same as hash_map.
Http://www.cnblogs.com/duzouzhe/archive/2010/01/12/1645191.html
Introduction to STL containers)