First, use std::d eque is better than std::vector when considering memory allocation and performance.
Deque Overview
Deque, like vectors, are the contents of the Standard Template Library, the deque is a two-terminal queue, which is very similar to vectors on an interface and can be directly replaced in many areas of operation. If the reader has been able to use vector containers effectively, the following provides deque member functions and operations for comparison purposes.
Function |
Describe |
C.assign (Beg,end) C.assign (N,elem) |
Assign the data in the [Beg end] interval to C. Assign a copy of n elem to C. |
c.at (IDX) |
Returns the data that the index IDX refers to, and throws the Out_of_range if the IDX crosses over. |
C.back () |
Returns the last data and does not check if the data exists. |
C.begin () |
Returns the iterator's one-valued data. |
C.clear () |
Removes all data from the container. |
Deque<elem> C Deque<elem> C1 (C2) Deque<elem> C (N) Deque<elem> c (n, Elem) Deque<elem> C (beg,end) C.~deque<elem> () |
Create an empty deque. Copy a deque. Creates a deque, contains n data, and the data is constructed by default. Create a deque that contains n-elem copies. Creates a deque in the [Beg;end] interval. Destroys all data and frees up memory. |
C.empty () |
Determines whether the container is empty. |
C.end () |
Point to the last data address in the iterator. |
C.erase (POS) C.erase (Beg,end) |
Deletes the data at the POS location and returns the location of the next data. Deletes the data from the [beg,end) interval and returns the location of the next data. |
C.front () |
Returns a data to the ground. |
Get_allocator |
Returns a copy using the constructor. |
C.insert (Pos,elem) C.insert (Pos,n,elem) C.insert (Pos,beg,end) |
Inserts a elem copy at the POS location and returns the new data location. Inserts >n elem data at the POS location. no return value. Inserts the data in the [Beg,end] interval at the POS position. no return value. |
C.max_size () |
Returns the maximum number of data in the container. |
C.pop_back () |
Deletes the last data. |
C.pop_front () |
Deletes the header data. |
C.push_back (Elem) |
Add a data to the tail. |
C.push_front (Elem) |
Inserts a data in the header. |
C.rbegin () |
Returns the first data of a reverse queue. |
C.rend () |
Returns the next position of the last data in a reverse queue. |
C.resize (num) |
Re-specify the length of the queue. |
C.size () |
Returns the number of actual data in the container. |
C1.swap (C2) Swap (C1,C2) |
Swap the C1 and C2 elements. Ditto operation. |