Singly Linked List Queue#
-
template<typename Elem>
class SLListQueue : public dsa::IQueue<Elem, SLListQueue># Singly linked list queue.
An unbounded, generic queue type that implements the Queue ADT
dsa::IQueue
using a singly, circularly linked list with a dummy header node. This class template statically inherits the Queue ADT template class using the Curiously Recurring Template Pattern (CRTP). The instantiated class type is both copyable and movable.Note
The queue elements have value semantics.
- Template Parameters:
Elem – The queue element type.
Private Functions
-
std::size_t size_() const noexcept#
Number of elements in the queue.
-
bool empty_() const noexcept#
Determines if this queue has no elements.
-
void iter_(std::function<void(Elem const&)> action) const#
Iterates over all elements of this queue from the front.
The given operation will be performed on each element iterated. It’s a no-op if this queue is empty.
- Parameters:
action – The operation to be performed on each element.
-
Elem &front_()#
Accesses the element at the front of this queue.
- Throws:
dsa::EmptyQueueError – if the queue is empty.
- Returns:
The front element.
-
Elem const &front_() const#
Accesses (read-only) the element at the front of this queue.
- Throws:
dsa::EmptyQueueError – if the queue is empty.
- Returns:
The front element (immutable).
-
void enqueue_(Elem const &elem)#
Adds an element to the end of this queue.
A deep copy of the element will be copy-constructed and then put into the queue.
- Parameters:
elem – The element to be added.
- Throws:
std::bad_alloc – or any exception thrown by the constuctor of type
Elem
.
-
void enqueue_(Elem &&elem)#
Adds an element to the end of this queue.
The element will be put into the queue using move semantics.
- Parameters:
elem – The element to be added.
- Throws:
std::bad_alloc – or any exception thrown by the constuctor of type
Elem
.
-
void dequeue_()#
Removes the element at end of this queue.
- Throws:
dsa::EmptyQueueError – if this queue is empty.
-
template<typename ...Args>
void emplace_(Args&&... args)# Creates a new element in-place after the last element of this queue.
The new element is constructed in-place using all of the arguments passed to this member function.
- Template Parameters:
Args – Types of the arguments to be passed to the constructor of the element type
Elem
.- Parameters:
args – Variable number of arguments to be passed to the constructor of the element type
Elem
.- Throws:
std::bad_alloc – or any exception thrown by the constuctor of type
Elem
.
-
struct Node#