Binary Search Tree (C++)
Loading...
Searching...
No Matches
Queue.cpp
Go to the documentation of this file.
1
14
15#include "Queue.h"
16#include <iostream>
17
22 // Remove all nodes from front to rear.
23 while (!isEmpty()) {
24 dequeue();
25 }
26}
27
32 QueueNode* q = new QueueNode(n);
33 if (!rear) {
34 front = rear = q;
35 }
36 else {
37 rear->next = q;
38 rear = q;
39 }
40}
41
46 if (!front) return nullptr;
47 QueueNode* temp = front;
48 Node* result = temp->data;
49 front = front->next;
50 if (!front) rear = nullptr;
51 delete temp;
52 return result;
53}
54
58bool Queue::isEmpty() const {
59 return front == nullptr;
60}
Declaration of the Queue class.
Represents a node within a binary search tree.
Definition Node.h:35
~Queue()
Destroys the Queue.
Definition Queue.cpp:21
Node * dequeue()
Removes and returns the node at the front of the queue.
Definition Queue.cpp:45
void enqueue(Node *n)
Adds a node to the end of the queue.
Definition Queue.cpp:31
bool isEmpty() const
Checks whether the queue is empty.
Definition Queue.cpp:58
Internal node type used by the Queue class.
Definition Queue.h:53