1 vector
Vector is equivalent to an array
Allocate a continuous memory space in the memory for storage. Storage with no vector size specified is supported. During internal implementation of STL, a very large memory space is allocated for storage, that is, the size returned by the capacituy () function, when the size of the allocated space is exceeded, a memory storage will be re-allocated. This gives us the feeling that the vector can be a continuous memory size without being specified. Generally, the default memory allocation can complete storage in most cases.
Advantages: (1) You can operate like an array without specifying the continuous storage of an array of memory size.
Dynamic operation. Usually reflected in push_back () pop_back ()
(2) convenient random access, that is, support for the [] Operator and vector. ()
(3) space saving.
Disadvantages: (1) low efficiency in performing internal insert/delete operations.
(2) Push and pop can only be performed at the end of the vector, and push and pop cannot be performed at the header of the vector.
(3) When the dynamically added data exceeds the size allocated by the vector by default, the whole data needs to be re-allocated, copied, and released.
2 list
Two-way linked list
Each node includes a fast info, a pre-pointer, and a post-drive pointer. You can easily add or delete memory without allocating the required memory size. Uses non-contiguous memory space for storage.
Advantages: (1) do not use continuous memory for dynamic operations.
(2) Easy internal insertion and deletion operations
(3) Push and pop can be performed on both ends
Disadvantages: (1) Internal Random Access is not allowed, that is, the [] Operator and vector. At () are not supported ()
(2) memory usage compared with verctor
3 deque
Double-end queue
Deque combines the vector and list functions.
Advantages: (1) convenient random access, that is, support for the [] Operator and vector. ()
(2) Easy internal insertion and deletion operations
(3) Push and pop can be performed on both ends
Disadvantages: (1) high memory usage
Usage differences:
1. If you need efficient instant access without worrying about the efficiency of insertion and deletion, use the Vector
2. If you need to insert and delete a large number of objects without having to access them immediately, you should use list
3 if you need to access data immediately and care about data insertion and deletion at both ends, use deque
========================================================== ====================================
Extension reference:
Cplusplus-list
Cplusplus-deque
Cplusplus-Vector
STL provides three basic containers: vector, list, And deque.