📅  最后修改于: 2020-12-15 04:30:26             🧑  作者: Mango
Deque是D ouble E nded Que ue的首字母缩写。它是一个序列容器,可以更改其运行时大小。容器是保存相同类型数据的对象。顺序容器严格按线性顺序存储元素。
双端队列的元素可以分散在不同的内存块中。容器存储必要的信息,以允许在恒定时间内直接访问任何元素。与向量不同,双端队列不能保证将其所有元素存储在连续的内存位置。因此,它不允许通过偏移指针直接访问数据。但是,它允许使用下标运算符[]直接访问任何元素。
在运行时,双端队列可以根据需要从两端收缩或扩展。内部分配器自动满足存储要求。 Deque提供与矢量类似的功能,但提供了从任何一端插入和删除数据的有效方法。
大小为零的双端队列也有效。在这种情况下,deque.begin()和deque.end()指向相同的位置。但是调用front()或back()的行为是不确定的。
以下是
template < class T, class Alloc = allocator > class deque;
T-所包含元素的类型。
T可以用任何其他数据类型(包括用户定义的类型)代替。
Alloc-分配器对象的类型。
默认情况下,使用分配器类模板,该模板定义了最简单的内存分配模型并且与值无关。
成员函数可以将以下成员类型用作参数或返回类型。
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | allocator_type | Alloc (Second parameter of the template) |
3 | reference | value_type& |
4 | const_reference | const value_type& |
5 | pointer | value_type* |
6 | const_pointer | const value_type* |
7 | iterator | a random access iterator to value_type |
8 | const_iterator | a random access iterator to const value_type |
9 | reverse_iterator | std::reverse_iterator |
10 | const_reverse_iterator | std::reverse_iterator |
11 | size_type | size_t |
12 | difference_type | ptrdiff_t |
以下是
Sr.No. | Method & Description |
---|---|
1 | deque::deque default constructor Constructs an empty deque with zero element. |
2 | deque::deque fill constructor
construct a new deque with n elements and assign val to each element of deque |
3 | deque::deque range constructor
Constructs a deque with as many elements as in range of first to last. |
4 | deque::deque copy constructor
Constructs a deque with copy of each elements present in existing container. |
5 | deque::deque move constructor
Constructs a deque with the contents of other using move semantics. |
6 | deque::deque initializer list constructor
Constructs a deque from initialize list. |
Sr.No. | Method & Description |
---|---|
1 | deque::~deque
Destroys deque object by deallocating it’s memory. |
Sr.No. | Method & Description |
---|---|
1 | deque::assign range version
Assign new values to the deque elements by replacing old ones. |
2 | deque::assign fill version
Assign new values to the deque elements by replacing old ones. |
3 | deque::assign initializer list version
Assign new values to the deque elements by replacing old ones. |
4 | deque::at
Returns reference to the element present at location n in the deque. |
5 | deque::back
Returns a reference to the last element of the deque. |
6 | deque::begin
Return a random access iterator pointing to the first element of the deque. |
7 | deque::cbegin
Returns a constant random access iterator which points to the beginning of the deque. |
8 | deque::cend
Returns a constant random access iterator which points to the beginning of the deque. |
9 | deque::clear
Destroys the deque by removing all elements from the deque and sets size of deque to zero. |
10 | deque::crbegin
Returns a constant reverse iterator which points to the reverser beginning of the container. |
11 | deque::crend
Returns a constant reverse iterator which points to the reverse end of the deque. |
12 | deque::emplace
Extends container by inserting new element at position. |
13 | deque::emplace_back
Inserts new element at the end of deque. |
14 | deque::emplace_front
Inserts new element at the beginning of deque. |
15 | deque::empty
Tests whether deque is empty or not. |
16 | deque::end
Returns an iterator which points to past-the-end element in the deque container. |
17 | deque::erase position version
Removes single element from the the deque. |
18 | deque::erase range version
Removes single element from the the deque. |
19 | deque::front
Returns a reference to the first element of the deque |
20 | deque::get_allocator
Returns an allocator associated with deque |
21 | deque::insert single element version
Extends container by inserting new element at position. |
22 | deque::insert fill version
Extends container by inserting new element in the container. |
23 | deque::insert range version
Extends container by inserting new element in the container. |
24 | deque::insert move version
Extends container by inserting new element in the container. |
25 | deque::insert initializer list version
Extends container by inserting new element in the container. |
26 | deque::max_size
Returns the maximum number of elements can be held by deque. |
27 | deque::operator= copy version
Assign new contents to the deque by replacing old ones and modifies size if necessary. |
28 | deque::operator= move version
Assign new contents to the deque by replacing old ones and modifies size if necessary. |
29 | deque::operator= initializer list version
Assign new contents to the deque by replacing old ones and modifies size if necessary. |
30 | deque::operator[]
Returns a reference to the element present at location n. |
31 | deque::pop_back
Removes last element from deque and reduces size of deque by one. |
32 | deque::pop_front
Removes first element from deque and reduces size of deque by one. |
33 | deque::push_back
Inserts new element at the end of deque and increases size of deque by one. |
34 | deque::push_back move version
Inserts new element at the end of deque and increases size of deque by one. |
35 | deque::push_front
Inserts new element at the front of deque and increases size of deque by one. |
36 | deque::push_front move version
Inserts new element at the front of deque and increases size of deque by one. |
37 | deque::rbegin
Returns a reverse iterator which points to the last element of the deque. |
38 | deque::rend
Returns a reverse iterator which points to the reverse end of the deque. |
39 | deque::resize
Changes the size of deque. |
40 | deque::resize value version
Changes the size of deque. |
41 | deque::shrink_to_fit
Requests the container to reduce it’s capacity to fit its size. |
42 | deque::size
Returns the number of elements present in the deque. |
43 | deque::swap
Exchanges the content of deque with contents of another deque x. |
Sr.No. | Method & Description |
---|---|
1 | operator==
Tests whether two deques are equal or not. |
2 | operator!=
Tests whether two deques are equal or not. |
3 | operator<
Tests whether first deque is less than other or not. |
4 | operator<=
Tests whether first deque is less than or equal to other or not. |
5 | operator>
Tests whether first deque is greater than other or not. |
6 | operator>=
Tests whether first deque is greater than or equal to other or not. |
7 | swap
Exchanges the contents of two deque. |