Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Queue.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/SList.h>
36
37namespace ogdf {
38
39
41
49template<class E>
50class QueuePure : private SListPure<E> {
51public:
53 using value_type = E;
55 using reference = E&;
57 using const_reference = const E&;
62
65
67 QueuePure(std::initializer_list<E> initList) : SListPure<E>(initList) { }
68
71
73
76 QueuePure(QueuePure<E>&& Q) : SListPure<E>(std::move(Q)) { }
77
80
86
88 bool empty() const { return SListPure<E>::empty(); }
89
92
95
98
101
103
108
111
114
117
120
123
126
129
132
134
139
143 return *this;
144 }
145
147
151 SListPure<E>::operator=(std::move(Q));
152 return *this;
153 }
154
156 const SListPure<E>& getListPure() const { return *this; }
157
159
164
166 iterator append(const E& x) { return SListPure<E>::pushBack(x); }
167
169
172 template<class... Args>
174 return SListPure<E>::emplaceBack(std::forward<Args>(args)...);
175 }
176
178 E pop() {
179 E x = top();
181 return x;
182 }
183
186
188};
189
191
199template<class E>
200class Queue : private SList<E> {
201public:
203 using value_type = E;
205 using reference = E&;
207 using const_reference = const E&;
212
214 Queue() { }
215
217 Queue(std::initializer_list<E> initList) : SList<E>(initList) { }
218
220 Queue(const Queue<E>& Q) : SList<E>(Q) { }
221
223
226 Queue(Queue<E>&& Q) : SList<E>(std::move(Q)) { }
227
229 ~Queue() { }
230
236
238 bool empty() const { return SList<E>::empty(); }
239
241 int size() const { return SList<E>::size(); }
242
244 const_reference top() const { return SList<E>::front(); }
245
248
251
254
256
261
264
267
270
272 iterator end() { return SList<E>::end(); }
273
275 const_iterator end() const { return SList<E>::end(); }
276
278 const_iterator cend() const { return SList<E>::cend(); }
279
282
285
287
292
296 return *this;
297 }
298
300
304 SList<E>::operator=(std::move(Q));
305 return *this;
306 }
307
309 const SList<E>& getList() const { return *this; }
310
312
317
319 iterator append(const E& x) { return SList<E>::pushBack(x); }
320
322
325 template<class... Args>
327 return SList<E>::emplaceBack(std::forward<Args>(args)...);
328 }
329
331 E pop() {
332 E x = top();
334 return x;
335 }
336
338 void clear() { SList<E>::clear(); }
339
341
343};
344
345// prints queue to output stream os using delimiter delim
346template<class E>
347void print(std::ostream& os, const QueuePure<E>& Q, char delim = ' ') {
348 print(os, Q.getListPure(), delim);
349}
350
351// prints queue to output stream os using delimiter delim
352template<class E>
353void print(std::ostream& os, const Queue<E>& Q, char delim = ' ') {
354 print(os, Q.getList(), delim);
355}
356
357// output operator
358template<class E>
359std::ostream& operator<<(std::ostream& os, const QueuePure<E>& Q) {
360 print(os, Q);
361 return os;
362}
363
364template<class E>
365std::ostream& operator<<(std::ostream& os, const Queue<E>& Q) {
366 print(os, Q);
367 return os;
368}
369
370}
Declaration of singly linked lists and iterators.
The parameterized class Queue<E> implements list-based queues.
Definition Queue.h:200
Queue()
Constructs an empty queue.
Definition Queue.h:214
const_reference bottom() const
Returns a reference to the back element.
Definition Queue.h:250
Queue(const Queue< E > &Q)
Constructs a queue that is a copy of Q.
Definition Queue.h:220
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition Queue.h:281
~Queue()
Destruction.
Definition Queue.h:229
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:269
Queue(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition Queue.h:217
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:266
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition Queue.h:272
iterator begin()
Returns an iterator to the first element of the queue.
Definition Queue.h:263
int size() const
Returns the number of elements in the queue.
Definition Queue.h:241
E & reference
Provides a reference to an element stored in a queue.
Definition Queue.h:205
const E & const_reference
Provides a reference to a const element stored in a queue for reading and performing const operations...
Definition Queue.h:207
void clear()
Makes the queue empty.
Definition Queue.h:338
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition Queue.h:284
E pop()
Removes front element and returns it.
Definition Queue.h:331
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition Queue.h:326
reference top()
Returns a reference to the front element.
Definition Queue.h:247
Queue(Queue< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition Queue.h:226
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:275
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:278
bool empty() const
Returns true iff the queue is empty.
Definition Queue.h:238
Queue< E > & operator=(const Queue< E > &Q)
Assignment operator.
Definition Queue.h:294
const_reference top() const
Returns a reference to the front element.
Definition Queue.h:244
iterator append(const E &x)
Adds x at the end of queue.
Definition Queue.h:319
reference bottom()
Returns a reference to the back element.
Definition Queue.h:253
Queue< E > & operator=(Queue< E > &&Q)
Assignment operator (move semantics).
Definition Queue.h:303
const SList< E > & getList() const
Conversion to const SList.
Definition Queue.h:309
E value_type
Represents the data type stored in a queue element.
Definition Queue.h:203
Implementation of list-based queues.
Definition Queue.h:50
void clear()
Makes the queue empty.
Definition Queue.h:185
reference top()
Returns a reference to the front element.
Definition Queue.h:94
~QueuePure()
Destruction.
Definition Queue.h:79
iterator end()
Returns an iterator to one-past-last element of the queue.
Definition Queue.h:119
const_iterator cend() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:125
iterator emplace(Args &&... args)
Adds a new element at the end of the queue.
Definition Queue.h:173
bool empty() const
Returns true iff the queue is empty.
Definition Queue.h:88
const E & const_reference
Provides a reference to a const element stored in a queue for reading and performing const operations...
Definition Queue.h:57
iterator append(const E &x)
Adds x at the end of queue.
Definition Queue.h:166
E pop()
Removes front element and returns it.
Definition Queue.h:178
iterator begin()
Returns an iterator to the first element of the queue.
Definition Queue.h:110
QueuePure(std::initializer_list< E > initList)
Constructs a queue and appends the elements in initList to it.
Definition Queue.h:67
reference bottom()
Returns a reference to the back element.
Definition Queue.h:100
E & reference
Provides a reference to an element stored in a queue.
Definition Queue.h:55
QueuePure()
Constructs an empty queue.
Definition Queue.h:64
QueuePure< E > & operator=(QueuePure< E > &&Q)
Assignment operator (move semantics).
Definition Queue.h:150
const_iterator end() const
Returns a const iterator to one-past-last element of the queue.
Definition Queue.h:122
QueuePure< E > & operator=(const QueuePure< E > &Q)
Assignment operator.
Definition Queue.h:141
const_iterator cbegin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:116
QueuePure(QueuePure< E > &&Q)
Constructs a queue containing the elements of Q (move semantics).
Definition Queue.h:76
const_reference bottom() const
Returns a reference to the back element.
Definition Queue.h:97
QueuePure(const QueuePure< E > &Q)
Constructs a queue that is a copy of Q.
Definition Queue.h:70
iterator backIterator()
Returns an iterator to the last element of the queue.
Definition Queue.h:128
E value_type
Represents the data type stored in a queue element.
Definition Queue.h:53
const SListPure< E > & getListPure() const
Conversion to const SListPure.
Definition Queue.h:156
const_iterator backIterator() const
Returns a const iterator to the last element of the queue.
Definition Queue.h:131
const_reference top() const
Returns a reference to the front element.
Definition Queue.h:91
const_iterator begin() const
Returns a const iterator to the first element of the queue.
Definition Queue.h:113
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:934
void clear()
Removes all elements from the list.
Definition SList.h:972
int size() const
Returns the number of elements in the list.
Definition SList.h:868
void popFront()
Removes the first element from the list.
Definition SList.h:953
SList< E > & operator=(const SList< E > &L)
Assignment operator.
Definition SList.h:881
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:927
Encapsulates a pointer to an ogdf::SList element.
Definition SList.h:92
Singly linked lists.
Definition SList.h:179
iterator backIterator()
Returns an iterator to the last element of the list.
Definition SList.h:368
void clear()
Removes all elements from the list.
Definition SList.h:555
iterator end()
Returns an iterator to one-past-last element of the list.
Definition SList.h:350
const_iterator cbegin() const
Returns a const iterator to the first element of the list.
Definition SList.h:344
const_iterator cend() const
Returns a const iterator to one-past-last element of the list.
Definition SList.h:362
bool empty() const
Returns true iff the list is empty.
Definition SList.h:226
iterator emplaceBack(Args &&... args)
Adds a new element at the end of the list.
Definition SList.h:484
SListPure< E > & operator=(const SListPure< E > &L)
Assignment operator.
Definition SList.h:404
const_reference front() const
Returns a reference to the first element.
Definition SList.h:245
const_reference back() const
Returns a reference to the last element.
Definition SList.h:263
iterator begin()
Returns an iterator to the first element of the list.
Definition SList.h:332
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:469
void popFront()
Removes the first element from the list.
Definition SList.h:519
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition Array.h:967
Definition GML.h:110