One of the secrets of Vector's excellent efficiency is the allocation of more memory than the element it accommodates.
Deque compared to vectors, the functional differences are as follows:
· Both ends are able to quickly insert elements and remove elements (vectors only at the tail end).
· Accessing the element is a bit slower than the vector, and there is a more indirect process.
· Deque does not support control over the timing of capacity and memory reallocation.
· The internal structure is a plurality of blocks, inserted before and after, is inserted in the beginning and ends of the block, full of part, and add one more block, so do not need to be like a vector, redistribution, replication.
Deque,vector and List comparison:
· Random access is good, but removing the insertion element in the middle is worse than list.
· Before and after inserting deque and list, the vector is inserted uniformly in the middle, and the insertion is the same for everyone.
Vector is a dynamic array;
Deque similar to a variable array of numbers;
List doubly linked list;
Summarize:
1. If you want to insert or remove frequently in the middle, you use the list.
2. If you are sure that you only need to insert at the tail, random access can be, you use the vector, but, with this, pay attention to his dynamic expansion, the best, to give him roughly the capacity to use;
3. If you need to insert at the tail, random access, then use Deque.
Similarities and differences of vector list deque