📅  最后修改于: 2020-12-15 04:34:43             🧑  作者: Mango
队列是一种数据结构,旨在在FIFO(先进先出)上下文中运行。在队列中,元素从后端插入,并从前端删除。
队列类是容器适配器。容器是保存相同类型数据的对象。可以从不同的序列容器创建队列。容器适配器不支持迭代器,因此我们不能将其用于数据操作。但是,它们分别支持push()和pop()成员函数用于数据插入和删除。
下面是
template > class queue;
T-所包含元素的类型。
T可以用任何其他数据类型(包括用户定义的类型)代替。
容器-基础容器对象的类型。
成员函数可以将以下成员类型用作参数或返回类型。
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | container_type | Second parameter of the template |
3 | size_type | size_t |
4 | reference | value_type& |
5 | const_reference | const value_type& |
6 | difference_type | ptrdiff_t |
以下是
Sr.No. | Method & Description |
---|---|
1 | queue::queue default constructor
Constructs an empty queue object, with zero elements. |
2 | queue::queue initialize constructor
Constructs a queue object and assigns internal container by a copy of ctnr. |
3 | queue::queue move constructor
Constructs the queue with the contents of other using move semantics. |
4 | queue::queue copy constructor
Constructs a queue with copy of each elements present in existing queue other. |
Sr.No. | Method & Description |
---|---|
1 | queue::~queue
Destroys queue by deallocating container memory. |
Sr.No. | Method & Description |
---|---|
1 | queue::back
Returns a reference to the last element of queue. |
2 | queue::emplace
Constructs and inserts new element at the end of queue. |
3 | queue::empty
Tests whether queue is empty or not. |
4 | queue::front
Returns a reference to the first element of the queue. |
5 | queue::operator= copy version
Assigns new contents to the queue by replacing old ones. |
6 | queue::operator= move version
Assigns new contents to the queue by replacing old ones. |
7 | queue::pop
Removes front element of the queue. |
8 | queue::push copy version
Inserts new element at the end of queue. |
9 | queue::push move version
Inserts new element at the end of queue. |
10 | queue::size
Returns the total number of elements present in the queue. |
11 | queue::swap
Exchanges the contents of queue with contents of another queue. |
Sr.No. | Method & Description |
---|---|
1 | operator==
Tests whether two queues are equal or not. |
2 | operator!=
Tests whether two queues are equal or not. |
3 | operator<
Tests whether first queue is less than other or not. |
4 | operator<=
Tests whether first queue is less than or equal to other or not. |
5 | operator>
Tests whether first queue is greater than other or not. |
6 | operator>=
Tests whether first queue is greater than or equal to other or not. |
7 | swap
Exchanges the contents of two queues. |
优先级队列是拥有优先级的队列数据结构。优先级队列类似于堆数据结构,在堆数据结构中,可以按任何顺序插入元素,并且始终首先检索最大堆元素。
以下是
template ,
class Compare = less < class priority_queue;
T-所包含元素的类型。
T可以用任何其他数据类型(包括用户定义的类型)代替。
容器-基础容器对象的类型。
比较-用于排序priority_queue的比较对象。
这可能是可以比较其两个参数的函数指针或函数对象。
成员函数可以将以下成员类型用作参数或返回类型。
Sr.No. | Member types | Definition |
---|---|---|
1 | value_type | T (First parameter of the template) |
2 | container_type | Second parameter of the template |
3 | size_type | size_t |
4 | reference | value_type& |
5 | const_reference | const value_type& |
6 | difference_type | ptrdiff_t |
以下是
Sr.No. | Method & Description |
---|---|
1 | priority_queue::priority_queue default constructor
Constructs an empty priority_queue with zero element. |
2 | priority_queue::priority_queue initialize constructor
Constructs a priority_queue object and assigns internal container by a copy of ctnr. |
3 | priority_queue::priority_queue range constructor
Constructs a priority_queue with as many elements in range of first to last. |
4 | priority_queue::priority_queue move constructor
Constructs the priority_queue with the contents of other using move semantics. |
5 | priority_queue::priority_queue copy constructor
Constructs a priority_queue with copy of each elements present in existing priority_queue other. |
Sr.No. | Method & Description |
---|---|
1 | priority_queue::~priority_queue
Destroys priority_queue by deallocating container memory. |
Sr.No. | Method & Description |
---|---|
1 | priority_queue::emplace
Constructs and inserts new element in sorted order in the priority_queue. |
2 | priority_queue::empty
Tests whether pritority_queue is empty or not. |
3 | priority_queue::operator= copy version
Assigns new contents to the priority_queue by replacing old ones. |
4 | priority_queue::operator= move version
Assigns new contents to the priority_queue by replacing old ones. |
5 | priority_queue::pop
Removes front element of the priority_queue. |
6 | priority_queue::push copy version
Inserts new element in sorted order. |
7 | priority_queue::push move version
Inserts new element in sorted order. |
8 | priority_queue::size
Returns the total number of elements present in the priority_queue. |
9 | priority_queue::swap
Exchanges the contents of priority_queue with contents of another priority_queue. |
10 | priority_queue::top
Returns a reference to the first element of the priority_queue |
Sr.No. | Method & Description |
---|---|
1 | swap
Exchanges the contents of priority_queue with contents of another priority_queue. |