A double-ended queue container is a queue that relaxes access rights. In addition to accessing elements from the header and tail of the queue, the standard double-ended queue also supports direct access by using the subscript operator "[]".
It provides direct access and sequential access methods. Its header file is <deque>.
1) constructors for double-ended queue containers
There are 4 forms of constructors:
Deque ();//Construct a double-ended queue container with size () 0
Deque (size_type n,const t& v=t ());//Initialize a double-ended queue of size n, the second parameter is the initial value of each element, and the object constructed by default is T ()
Deque (const deque& x);//copy constructor, using double-ended queue X to initialize this double-ended queue container
Deque (Const_iterator first,const_iterator last);//Select a section from another container that supports const_iterator to create a new double-ended queue container.
2) using a double-ended queue container
A, access to the double-ended queue container information
For a double-ended queue container,
Size () returns the number of elements in the double-ended queue container;
Max_size () returns the maximum number of elements that can be accommodated in a double-ended queue container;
Empty () returns True when there are no elements in the double-ended queue
B. Placing elements in a double-ended queue container
There are several ways to put elements into a double-ended queue container: constructors, Push_back () methods, insert () methods, [] operators, = operators, swap functions. There is also the Push_front function, whose prototype is:
void Push_front (const t& x);//add element x to the head of the double-ended queue container
C. Remove elements from the double-ended queue container
Using Pop_back (), Pop_front (), Erase (), clear (), you can remove elements from a double-ended queue, and a pop_front () function, compared to a vector container, is a prototype:
void Pop_front ();//Delete the most front-end element in a double-ended queue container
D. Accessing elements in a double-ended queue container
The double-ended queue container can be accessed sequentially or directly. Elements in a double-ended queue container can be combined using Pop_front (), Pop_back (), Front (), back () member functions for sequential access, or you can use iterators to sequentially traverse a double-ended queue. Because of the support for random access iterators, random access is possible.
8. Generic programming and C + + Standard Template Library 2.3 Dual-ended queue container