ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Dequeue.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File Dequeue.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
28/*--------------------------------------------------------------------------*/
29/*----------------------------- DEFINITIONS --------------------------------*/
30/*--------------------------------------------------------------------------*/
31
32#ifndef __ADS_Dequeue
33 #define __ADS_Dequeue
34/* self-identification: #endif constant */
35
36/*--------------------------------------------------------------------------*/
37/*------------------------------ INCLUDES ----------------------------------*/
38/*--------------------------------------------------------------------------*/
39
40#include "ADS/Contract.h"
41#include "ADS/sequence/List.h"
42
43#include <cstddef>
44
45/*--------------------------------------------------------------------------*/
46/*--------------------------- NAMESPACE ------------------------------------*/
47/*--------------------------------------------------------------------------*/
48
49namespace ADS
50{
51
52/*--------------------------------------------------------------------------*/
53/*----------------------------- CLASS Dequeue ------------------------------*/
54/*--------------------------------------------------------------------------*/
55
57template< class T >
59{
60
61/*--------------------------------------------------------------------------*/
62 public:
63 using Item = T;
64
66 [[nodiscard]] bool empty( void ) const;
67
78 void insertHead( const T & v );
79
90 void insertTail( const T & v );
91
103 T removeHead( void );
104
116 T removeTail( void );
117
120 [[nodiscard]] const T & head( void ) const;
121
124 [[nodiscard]] const T & tail( void ) const;
125
126/*------------------------- THE STANDARD INTERFACE -------------------------*/
127
128 // the bidirectional iterators of the list, from the head to the tail
129
131 using value_type = T;
133 using size_type = std::size_t;
135 using difference_type = std::ptrdiff_t;
137 using reference = T &;
139 using const_reference = const T &;
148
150 [[nodiscard]] iterator begin( void ) { return( f_L.begin() ); }
152 [[nodiscard]] iterator end( void ) { return( f_L.end() ); }
154 [[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
156 [[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
158 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
160 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
162 [[nodiscard]] reverse_iterator rbegin( void ) { return( f_L.rbegin() ); }
164 [[nodiscard]] reverse_iterator rend( void ) { return( f_L.rend() ); }
166 [[nodiscard]] const_reverse_iterator rbegin( void ) const {
167 return( f_L.rbegin() );
168 }
169
170 [[nodiscard]] const_reverse_iterator rend( void ) const {
171 return( f_L.rend() );
172 }
173
175 void push_back( const T & v ) { insertTail( v ); }
176
178 void push_front( const T & v ) { insertHead( v ); }
179
180/*--------------------------------------------------------------------------*/
181 private:
182 List< T > f_L;
183
184 }; // end( class Dequeue )
185
186/*--------------------------------------------------------------------------*/
187
188} // end( namespace ADS )
189
190/*--------------------------------------------------------------------------*/
191/*-------------------------- IMPLEMENTATION --------------------------------*/
192/*--------------------------------------------------------------------------*/
193
194#include "ADS/queue/impl/Dequeue.tpp"
195
196/*--------------------------------------------------------------------------*/
197
198#endif /* Dequeue.h included */
199
200/*--------------------------------------------------------------------------*/
201/*--------------------------- End File Dequeue.h ---------------------------*/
202/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
a DEQUEUE on a bidirectional list with pointers
Definition Dequeue.h:59
T Item
the type of the items
Definition Dequeue.h:63
const T & head(void) const
the item at the head
typename List< T >::reverse_iterator reverse_iterator
the iterator on the items, backwards
Definition Dequeue.h:145
const_iterator begin(void) const
the constant iterator on the first item
Definition Dequeue.h:154
void push_back(const T &v)
insertTail(), for std::back_inserter
Definition Dequeue.h:175
void insertTail(const T &v)
puts at the tail, before the sentinel of the list
typename List< T >::const_iterator const_iterator
the iterator on the constant items
Definition Dequeue.h:143
const_iterator cbegin(void) const
the constant iterator on the first item
Definition Dequeue.h:158
std::ptrdiff_t difference_type
the type of the distances
Definition Dequeue.h:135
const_iterator cend(void) const
the constant iterator past the last item
Definition Dequeue.h:160
T removeTail(void)
removes the item at the tail and returns it
const T & const_reference
a constant reference to an item
Definition Dequeue.h:139
T removeHead(void)
removes the item at the head and returns it
const T & tail(void) const
the item at the tail
iterator begin(void)
the iterator on the first item
Definition Dequeue.h:150
const_reverse_iterator rend(void) const
the constant iterator before the first item, backwards
Definition Dequeue.h:170
std::size_t size_type
the type of the sizes
Definition Dequeue.h:133
void insertHead(const T &v)
puts at the head, insert( head() , v ) of the list
const_iterator end(void) const
the constant iterator past the last item
Definition Dequeue.h:156
const_reverse_iterator rbegin(void) const
the constant iterator on the last item, backwards
Definition Dequeue.h:166
typename List< T >::const_reverse_iterator const_reverse_iterator
the iterator on the constant items, backwards
Definition Dequeue.h:147
typename List< T >::iterator iterator
the iterator on the items
Definition Dequeue.h:141
T value_type
the type of the items
Definition Dequeue.h:131
void push_front(const T &v)
insertHead(), for std::front_inserter
Definition Dequeue.h:178
iterator end(void)
the iterator past the last item
Definition Dequeue.h:152
bool empty(void) const
true if there is no item
T & reference
a reference to an item
Definition Dequeue.h:137
reverse_iterator rbegin(void)
the iterator on the last item, backwards
Definition Dequeue.h:162
reverse_iterator rend(void)
the iterator before the first item, backwards
Definition Dequeue.h:164
a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled
Definition List.h:118
Iterator< true > const_iterator
the iterator on the constant items
Definition List.h:324
std::reverse_iterator< iterator > reverse_iterator
the iterator on the items, backwards
Definition List.h:326
Iterator< false > iterator
the iterator on the items
Definition List.h:322
std::reverse_iterator< const_iterator > const_reverse_iterator
the iterator on the constant items, backwards
Definition List.h:328
Definition ADT.h:96