forked from CSUF-CPSC-131-Fall2019/Data-Structures-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueLinkedList.hpp
More file actions
37 lines (30 loc) · 887 Bytes
/
QueueLinkedList.hpp
File metadata and controls
37 lines (30 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include "SinglyLinkedList.hpp"
#include <stdexcept>
template<typename T>
class QueueLinkedList {
private:
SinglyLinkedList<T> list;
public:
QueueLinkedList() = default;
void push( const T& x); // Inserts x at end of the queue
void pop(); // Removes item at front of queue
T& peek(); // Returns but does not remove item at the front of the queue
bool empty(); // Returns true if queue has no items
};
template<typename T>
void QueueLinkedList<T>::push( const T& newItem ) {
list.append(newItem); // Insert as list tail (end of queue)
}
template<typename T>
void QueueLinkedList<T>::pop() {
list.removeAfter(nullptr); // Remove list head
}
template<typename T>
T& QueueLinkedList<T>::peek() {
return list.front();
}
template<typename T>
bool QueueLinkedList<T>::empty() {
return list.empty();
}