Deque (including the header file #include<deque>) is made up of several contiguous spaces, and once it is necessary to add new space at the head or end of the deque, a fixed amount of contiguous space is configured to thread the head or tail of the deque. Deque's biggest task is to maintain the illusion of its overall continuity in these segmented contiguous spaces, and provide a random access interface.
As a matter of fact. A map is maintained inside the deque (note!) Not a map container in the STL) is a small contiguous space in which each element is a pointer to another (larger) area called a buffer, which is used to hold the data in the deque. As a result, deque randomly accesses and traverses data more slowly than vectors. It inserts an element for the first time and dynamically allocates 512 bytes of space by default, and when that 512 bytes of space is exhausted, it dynamically allocates its own additional 512-byte space, and then it is connected to the virtual. This design of deque makes it a much more complex architecture, algorithm, and iterator design than vector. Its random access and traversal performance is worse than vector.
Deque is an optimized basic sequence container for adding and deleting operations on both ends of a sequence. Usually consists of some independent blocks, the first chunk expands in some direction, and the last chunk expands toward the other side. It allows for faster random access, but it does not keep all objects in a contiguous block of memory like a vector, but multiple contiguous blocks of memory. And keep track of these blocks and the order in a mapping structure.
1 //Queue Declaration2deque<int>Q;3 4 //insert an element in front of5 Q.push_front ();6 7 //Insert an element to the back8 Q.push_back ();9 Ten //Delete the previous element One Q.pop_front (); A - //remove one of the following elements - Q.pop_back (); the - //Team Top Elements - Q.front (); - + //Team Tail Elements -Q.back ();
C + + of Deque