ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
MinDeque.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File MinDeque.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
34/*--------------------------------------------------------------------------*/
35/*----------------------------- DEFINITIONS --------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38#ifndef __ADS_MinDeque
39 #define __ADS_MinDeque
40/* self-identification: #endif constant */
41
42/*--------------------------------------------------------------------------*/
43/*------------------------------ INCLUDES ----------------------------------*/
44/*--------------------------------------------------------------------------*/
45
46#include "ADS/Contract.h"
47#include "ADS/Portable.h"
48#include "ADS/stack/MinStack.h"
49
50#include <cstddef>
51#include <functional>
52#include <utility>
53#include <vector>
54
55/*--------------------------------------------------------------------------*/
56/*--------------------------- NAMESPACE ------------------------------------*/
57/*--------------------------------------------------------------------------*/
58
59namespace ADS
60{
61
62/*--------------------------------------------------------------------------*/
63/*----------------------------- CLASS MinDeque -----------------------------*/
64/*--------------------------------------------------------------------------*/
65
68template< class T , class C = std::less<> >
70{
71
72/*--------------------------------------------------------------------------*/
73 public:
74 using Item = T;
75
77 explicit MinDeque( C less = C() )
78 : f_F( less ) , f_B( less ) , f_less( less ) { }
79
81 [[nodiscard]] bool empty( void ) const {
82 return( f_F.empty() && f_B.empty() );
83 }
84
86 [[nodiscard]] std::size_t size( void ) const {
87 return( f_F.size() + f_B.size() );
88 }
89
91 void push_front( const T & x ) { f_F.push( x ); }
92
94 void push_back( const T & x ) { f_B.push( x ); }
95
110 T pop_front( void );
111
116 T pop_back( void );
117
120 [[nodiscard]] const T & front( void ) const;
121
124 [[nodiscard]] const T & back( void ) const;
125
128 [[nodiscard]] const T & min( void ) const;
129
131 void clear( void ) {
132 f_F.clear();
133 f_B.clear();
134 }
135
136/*--------------------------------------------------------------------------*/
137 private:
152 static void deal( MinStack< T , C > & s , MinStack< T , C > & t );
153
156 ADS_NO_UNIQUE_ADDRESS C f_less;
157
158 }; // end( class MinDeque )
159
160/*--------------------------------------------------------------------------*/
161
162} // end( namespace ADS )
163
164/*--------------------------------------------------------------------------*/
165/*-------------------------- IMPLEMENTATION --------------------------------*/
166/*--------------------------------------------------------------------------*/
167
168#include "ADS/queue/impl/MinDeque.tpp"
169
170/*--------------------------------------------------------------------------*/
171
172#endif /* MinDeque.h included */
173
174/*--------------------------------------------------------------------------*/
175/*-------------------------- End File MinDeque.h ---------------------------*/
176/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The STACK with the minimum of exercise 3.14 of Morin's book, beyond the book [see ADT....
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
bool empty(void) const
true if there is no item
Definition MinDeque.h:81
T pop_front(void)
removes the item at the front and returns it
void clear(void)
removes all the items
Definition MinDeque.h:131
T pop_back(void)
removes the item at the back and returns it, the mirror of pop_front()
void push_front(const T &x)
at the front
Definition MinDeque.h:91
T Item
the type of the items
Definition MinDeque.h:74
const T & min(void) const
the least item, the lesser of the minima of the two stacks
const T & front(void) const
the item at the front
const T & back(void) const
the item at the back
void push_back(const T &x)
at the back
Definition MinDeque.h:94
std::size_t size(void) const
the number of items
Definition MinDeque.h:86
MinDeque(C less=C())
the empty deque, ordered by less
Definition MinDeque.h:77
a STACK with its least item in time
Definition MinStack.h:69
#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
Definition ADT.h:96