1VectorThe vector corresponds to an array
Allocates a contiguous memory space in memory for storage. Supports storage that does not specify a vector size. STL internal implementation, first allocate a very large memory space to store, that is, the size of the Capacituy () function return, when more than this allocated space to redistribute a piece of memory storage, this gives a vector can not specify a vector that is the size of a contiguous memory. Typically, this default memory allocation completes most of the storage.
Advantages: (1) No contiguous storage of an array of memory size is specified, that is, it can be manipulated like an array, but the array can be
For dynamic operation. Usually embodied in push_back () Pop_back ()
(2) Convenience of random access, that is, support [] operator and vector.at ()
(3) Space saving.
Disadvantages: (1) The internal insertion delete operation is inefficient.
(2) Push and pop can only be done at the end of the vector and cannot be pushed and pop on the Vector's head.
(3) When the dynamically added data exceeds the vector default allocation size, the overall redistribution, copying and interpretation
Put
2List
Two-way linked list
Each node includes a info Quick info, a precursor pointer pre, and a rear-drive pointer post. You can add and remove operations without allocating the required memory size. is stored in a non contiguous memory space.
Advantages: (1) Do not use continuous memory to complete dynamic operation.
(2) Easy to insert and delete within the internal operation
(3) can be push at both ends, pop
Disadvantages: (1) cannot carry on the internal random access, namely does not support [] the operator and the vector.at ()
(2) compared with the verctor to occupy more memory
3deque
Double-end queue with two-terminal queues
The deque incorporates vectors and lists on a functional list.
Advantages: (1) Random access convenience, that is, support [] operator and vector.at ()
(2) Easy to insert and delete within the internal operation
(3) can be push at both ends, pop
Disadvantages: (1) occupy more memory
Use the difference:
1 If you need efficient and immediate access without caring about the efficiency of insertions and deletions, use vector
2 If you need a lot of insertions and deletions without concern for immediate access, you should use the list
3 If you need immediate access and care about inserting and deleting data at both ends, you should use the Deque