Deque of C ++ STL containers
Compared with the vector container, deque dual-end queue container has the obvious advantage of efficiently adding and deleting the first and last elements, and is easy to insert elements at any position.
Adding an element at the beginning and end of the deque container will not invalidate any iterator, but deleting an element at the beginning and end will invalidate the iterator pointing to the deleted element, adding or deleting any other location in the deque container will invalidate all iterators of the container.
1. deque create object
(1) deque <int> de; // create an empty deque object
(2) deque <int> de (n); // create a deque object with n elements
(3) deque <int> de (n, value); // create a deque with n elements. The initial value of each element is value.
(4) deque <int> de1 (n, value); deque <int> de2 (D1); // copy each element value of a deque object and create a new deque object
(5) int iarray [] = {1, 2, 3}; deque <int> de (iarray, iarray + 3); // copy iterator range [first, last) to create a new deque object.
2. Common deque Functions
(1) void push_back (const T &) // Insert a new element value at the end of the container
(2) void push_front (const T &) // Insert a new element value at the beginning of the container
(3) void pop_front () deletes the first element of deque
(4) void pop_back () Delete the last element of deque
(5) iterator erase (iterator POS) deletes the elements referred to by the iterator POS
(6) iterator erase (iterator first, iterator last) deletes all elements of the iterator range [first, last)
(7) void clear () call the erase function to clear all elements
(8) reverse_iterator rbegin () // reverse traversal from the end
(9) reverse_iterator rend () // reverse traversal from the header
(10) void swap (deque &) // used for deque exchange
(11) bool empty ()
(12) size_type size ()
(13) size_type max_size ()
(14) Reference Front ()
(15) reference back ()