C++ Library - <deque>

Deque is acronym for Double Ended Queue. It is a sequence container that can change it's size runtime. Container is an object that holds data of same type. Sequence containers store elements strictly in linear sequence.
Elements of deque can be scattered in different chunks of memory. Container stores necessary information to allow direct access to any element in constant time. Unlike vectors, deque are not guaranteed to store all it's element at contiguous memory locations. Hence it does not allow direct access to data by offsetting pointers. But it enables direct access to any element using subscript operator [ ].
Deque can shrink or expand as needed from both ends at run time. The storage requirement is fulfilled automatically by internal allocator. Deque provides similar functionality as vectors, but provides efficient way to insert and delete data from any end.
Zero sized deques are also valid. In that case deque.begin() and deque.end() points to same location. But behavior of calling front() or back() is undefined.
Below is definition of std::deque from <deque> header file
template < class T, class Alloc = allocator<T> > class deque;

T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
T − Type of the element contained.
T may be substituted by any other data type including user-defined type.
Alloc − Type of allocator object.
By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Alloc − Type of allocator object.
By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.
Following member types can be used as parameters or return type by member functions.
Below is list of all methods from <deque> header.
Constructs an empty deque with zero element.
construct a new deque with n elements and assign val to each element of deque
Constructs a deque with as many elements as in range of first to last.
Constructs a deque with copy of each elements present in existing container.
Constructs a deque with the contents of other using move semantics.
Constructs a deque from initialize list.
Destroys deque object by deallocating it's memory.
Assign new values to the deque elements by replacing old ones.
Assign new values to the deque elements by replacing old ones.
Assign new values to the deque elements by replacing old ones.
Returns reference to the element present at location n in the deque.
Returns a reference to the last element of the deque.
Return a random access iterator pointing to the first element of the deque.
Returns a constant random access iterator which points to the beginning of the deque.
Returns a constant random access iterator which points to the beginning of the deque.
Destroys the deque by removing all elements from the deque and sets size of deque to zero.
Returns a constant reverse iterator which points to the reverser beginning of the container.
Returns a constant reverse iterator which points to the reverse end of the deque.
Extends container by inserting new element at position.
Inserts new element at the end of deque.
Inserts new element at the beginning of deque.
Tests whether deque is empty or not.
Returns an iterator which points to past-the-end element in the deque container.
Removes single element from the the deque.
Removes single element from the the deque.
Returns a reference to the first element of the deque
Returns an allocator associated with deque
Extends container by inserting new element at position.
Extends container by inserting new element in the container.
Extends container by inserting new element in the container.
Extends container by inserting new element in the container.
Extends container by inserting new element in the container.
Returns the maximum number of elements can be held by deque.
Assign new contents to the deque by replacing old ones and modifies size if necessary.
Assign new contents to the deque by replacing old ones and modifies size if necessary.
Assign new contents to the deque by replacing old ones and modifies size if necessary.
Returns a reference to the element present at location n.
Removes last element from deque and reduces size of deque by one.
Removes first element from deque and reduces size of deque by one.
Inserts new element at the end of deque and increases size of deque by one.
Inserts new element at the end of deque and increases size of deque by one.
Inserts new element at the front of deque and increases size of deque by one.
Inserts new element at the front of deque and increases size of deque by one.
Returns a reverse iterator which points to the last element of the deque.
Returns a reverse iterator which points to the reverse end of the deque.
Changes the size of deque.
Changes the size of deque.
Requests the container to reduce it's capacity to fit its size.
Returns the number of elements present in the deque.
Exchanges the content of deque with contents of another deque x.
Tests whether two deques are equal or not.
Tests whether two deques are equal or not.
Tests whether first deque is less than other or not.
Tests whether first deque is less than or equal to other or not.
Tests whether first deque is greater than other or not.
Tests whether first deque is greater than or equal to other or not.
Exchanges the contents of two deque.
 Print
 Add Notes
 Bookmark this page