ADS
Algorithms and Data Structures
Toggle main menu visibility
Loading...
Searching...
No Matches
MinQueue.h
Go to the documentation of this file.
1
/*--------------------------------------------------------------------------*/
2
/*---------------------------- File MinQueue.h -----------------------------*/
3
/*--------------------------------------------------------------------------*/
33
/*--------------------------------------------------------------------------*/
34
/*----------------------------- DEFINITIONS --------------------------------*/
35
/*--------------------------------------------------------------------------*/
36
37
#ifndef __ADS_MinQueue
38
#define __ADS_MinQueue
39
/* self-identification: #endif constant */
40
41
/*--------------------------------------------------------------------------*/
42
/*------------------------------ INCLUDES ----------------------------------*/
43
/*--------------------------------------------------------------------------*/
44
45
#include "
ADS/Contract.h
"
46
#include "
ADS/Portable.h
"
47
#include "
ADS/stack/MinStack.h
"
48
49
#include <cstddef>
50
#include <functional>
51
#include <utility>
52
53
/*--------------------------------------------------------------------------*/
54
/*--------------------------- NAMESPACE ------------------------------------*/
55
/*--------------------------------------------------------------------------*/
56
57
namespace
ADS
58
{
59
60
/*--------------------------------------------------------------------------*/
61
/*----------------------------- CLASS MinQueue -----------------------------*/
62
/*--------------------------------------------------------------------------*/
63
65
template
<
class
T ,
class
C = std::less<> >
66
class
MinQueue
67
{
68
69
/*--------------------------------------------------------------------------*/
70
public
:
71
using
Item
= T;
72
74
explicit
MinQueue
( C less = C() )
75
: f_I( less ) , f_O( less ) , f_less( less ) { }
76
78
[[nodiscard]]
bool
empty
(
void
)
const
{
79
return
( f_I.empty() && f_O.empty() );
80
}
81
83
[[nodiscard]] std::size_t
size
(
void
)
const
{
84
return
( f_I.size() + f_O.size() );
85
}
86
89
void
enqueue
(
const
T & x );
90
106
T
dequeue
(
void
);
107
111
[[nodiscard]]
const
T &
top
(
void
)
const
;
112
115
[[nodiscard]]
const
T &
min
(
void
)
const
;
116
118
void
clear
(
void
) {
119
f_I.clear();
120
f_O.clear();
121
}
122
123
/*--------------------------------------------------------------------------*/
124
private
:
126
void
transfer(
void
);
127
128
MinStack< T , C >
f_I;
129
MinStack< T , C >
f_O;
130
ADS_NO_UNIQUE_ADDRESS
C f_less;
131
132
};
// end( class MinQueue )
133
134
/*--------------------------------------------------------------------------*/
135
136
}
// end( namespace ADS )
137
138
/*--------------------------------------------------------------------------*/
139
/*-------------------------- IMPLEMENTATION --------------------------------*/
140
/*--------------------------------------------------------------------------*/
141
142
#include "ADS/queue/impl/MinQueue.tpp"
143
144
/*--------------------------------------------------------------------------*/
145
146
#endif
/* MinQueue.h included */
147
148
/*--------------------------------------------------------------------------*/
149
/*-------------------------- End File MinQueue.h ---------------------------*/
150
/*--------------------------------------------------------------------------*/
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
MinStack.h
The STACK with the minimum of exercise 3.14 of Morin's book, beyond the book [see ADT....
Portable.h
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
ADS::MinQueue::dequeue
T dequeue(void)
removes the item at the front and returns it, from the stack , which takes the items of when it is e...
ADS::MinQueue::MinQueue
MinQueue(C less=C())
the empty queue, ordered by less
Definition
MinQueue.h:74
ADS::MinQueue::min
const T & min(void) const
the least item, the lesser of the minima of the two stacks
ADS::MinQueue::enqueue
void enqueue(const T &x)
at the back, on the stack
ADS::MinQueue::size
std::size_t size(void) const
the number of items
Definition
MinQueue.h:83
ADS::MinQueue::Item
T Item
the type of the items
Definition
MinQueue.h:71
ADS::MinQueue::clear
void clear(void)
removes all the items
Definition
MinQueue.h:118
ADS::MinQueue::empty
bool empty(void) const
true if there is no item
Definition
MinQueue.h:78
ADS::MinQueue::top
const T & top(void) const
the item at the front, the top of or the bottom of if is empty
ADS::MinStack
a STACK with its least item in time
Definition
MinStack.h:69
ADS_NO_UNIQUE_ADDRESS
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition
Portable.h:81
ADS
Definition
ADT.h:96
ADS
queue
MinQueue.h
Generated by
1.17.0