13 template <
typename ValueType>
67 template <
typename ValueType>
72 template <
typename ValueType>
77 template <
typename ValueType>
82 template <
typename ValueType>
85 ringBuffer = std::vector<ValueType>(capacity);
91 template <
typename ValueType>
93 if (count >= capacity - 1)
94 expandRingBufferCapacity();
96 ringBuffer[rear] = value;
97 rear = (rear + 1) % capacity;
101 template <
typename ValueType>
104 throw std::runtime_error(
"dequeue: Attempting to dequeue an empty queue");
106 ValueType result = ringBuffer[front];
107 front = (front + 1) % capacity;
112 template <
typename ValueType>
115 throw std::runtime_error(
"peek: Attempting to peek at an empty queue");
116 return ringBuffer.get(front);
119 template <
typename ValueType>
122 throw std::runtime_error(
"front: Attempting to read front of an empty queue");
123 return ringBuffer[front];
126 template <
typename ValueType>
129 throw std::runtime_error(
"back: Attempting to read back of an empty queue");
130 return ringBuffer[(rear + capacity - 1) % capacity];
133 template <
typename ValueType>
135 std::vector<ValueType> copyBuffer = ringBuffer;
136 ringBuffer = std::vector<ValueType>(2 * capacity);
137 for (
int i = 0; i < count; i++) {
138 ringBuffer[i] = copyBuffer[(front + i) % capacity];
This file exports the constants used in throughout the project.
const int INITIAL_QUEUE_CAPACITY
Constants for Queue.
This class models a linear structure called a Queue.
int front
index to front of the queue
int capacity
capacity of the queue
std::vector< ValueType > ringBuffer
Vector of ValueType for Circular Queue.
void expandRingBufferCapacity()
This private method doubles the capacity of the ringBuffer vector.
int count
number of value in the queue
void clear()
Removes all elements from the queue.
ValueType dequeue()
Removes and returns the first item in the queue.
virtual ~Queue()=default
Frees any heap storage associated with this queue.
void enqueue(const ValueType &value)
Adds value to the end of the queue.
Queue()
Initializes a new empty queue.
int rear
index to rear of the queue