a QUEUE with its least item in \( O( 1 ) \) amortized time
More...
#include <ADS/queue/MinQueue.h>
|
| using | Item = T |
| | the type of the items
|
|
| | MinQueue (C less=C()) |
| | the empty queue, ordered by less
|
| bool | empty (void) const |
| | true if there is no item
|
| std::size_t | size (void) const |
| | the number \( n \) of items
|
| void | enqueue (const T &x) |
| | \( x \) at the back, on the stack \( I \)
|
| T | dequeue (void) |
| | removes the item at the front and returns it, from the stack \( O \), which takes the items of \( I \) when it is empty
|
| const T & | top (void) const |
| | the item at the front, the top of \( O \) or the bottom of \( I \) if \( O \) is empty
|
| const T & | min (void) const |
| | the least item, the lesser of the minima of the two stacks
|
| void | clear (void) |
| | removes all the items
|
template<class T, class C = std::less<>>
class ADS::MinQueue< T, C >
a QUEUE with its least item in \( O( 1 ) \) amortized time
◆ Item
template<class T, class C = std::less<>>
◆ MinQueue()
template<class T, class C = std::less<>>
the empty queue, ordered by less
◆ clear()
template<class T, class C = std::less<>>
◆ dequeue()
template<class T, class C = std::less<>>
removes the item at the front and returns it, from the stack \( O \), which takes the items of \( I \) when it is empty
In pseudocode (Morin, exercise 3.15):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{dequeue}() \cr
2 & \quad \textbf{if}\ O = \emptyset\ \textbf{then}\ \textbf{while}
\ I \ne \emptyset\ \textbf{do}\ \mathrm{push}( O , \mathrm{pop}( I )
) \cr
3 & \quad \textbf{return}\ \mathrm{pop}( O )
\end{array}}
\]
- Precondition
- the queue is not empty
- Postcondition
- one item less
◆ empty()
template<class T, class C = std::less<>>
◆ enqueue()
template<class T, class C = std::less<>>
\( x \) at the back, on the stack \( I \)
- Postcondition
- one item more
◆ min()
template<class T, class C = std::less<>>
the least item, the lesser of the minima of the two stacks
- Precondition
- the queue is not empty
◆ size()
template<class T, class C = std::less<>>
the number \( n \) of items
◆ top()
template<class T, class C = std::less<>>
the item at the front, the top of \( O \) or the bottom of \( I \) if \( O \) is empty
- Precondition
- the queue is not empty
The documentation for this class was generated from the following file: