In depth analysis of the use of deque in C++

  • 2020-04-01 21:40:20
  • OfStack

First, STD ::deque is better than STD ::vector when considering memory allocation and execution performance.

A Deque overview

Deque, like vector, is the content of the standard template library. Deque is a double-ended queue, which is very similar to vector in interface and can be directly replaced in many operations. Provided that the reader has been able to use the vector container effectively, the member functions and operations of deque are provided below for comparison.

function describe C.a. ssign (beg, end)
C.a. ssign (n, elem)   Assign the data in the [beg; end) interval to c.
Assign n copies of elem to c. T (c.a. independence idx)   Returns the data referred to by the index idx, throwing out_of_range if idx crosses the line. Mount an ack ()   Returns the last data, without checking for its existence. Mount do v.begin ()   Returns the weight of the iterator. Arthur c. Lear ()   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.
Create a deque with n data, all of which are generated by default.
Create a deque with n copies of elem.
Create a deque with the section beg;end.
Destroy all data and free memory. C.e mpty ()   Determines if the container is empty. C.e nd ()   Points to the last data address in the iterator. C.e rase (pos)
C.e rase (beg, end)   Delete the data of the pos location and return the location of the next data.
Delete the data in the [beg,end) interval and return the location of the next data. C.f ront ()   Returns a data. Get_allocator   Returns a copy using the constructor. C.i nsert (pos, elem)  
C.i nsert (pos, n, elem)
C.i nsert (pos, beg, end) Insert a copy of elem at the pos location and return the new data location.
Insert > at pos position; N elem data. No return value.
Insert data in the [beg,end) interval at the pos position. No return value. C. ax_size ()   Returns the maximum amount of data in the container. C.p op_back ()   Delete the last data. C.p op_front ()   Delete header data. C.p ush_back (elem)   Add a number to the tail. C.p ush_front (elem)   Insert a data in the header. C.r the begin ()   Returns the first data from an inverse queue. C.r end ()   Returns the next location of the last data in an inverse queue. C.r esize (num)   Respecify the length of the queue. C.s. considering ()   Returns the number of actual data in the container. C1. Swap (c2)  
Swap (c1 and c2) I'm going to swap the c1 and c2 elements.
Same as above.

Related articles: