-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.cpp
More file actions
59 lines (54 loc) · 1.37 KB
/
Copy pathQueue.cpp
File metadata and controls
59 lines (54 loc) · 1.37 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include "Queue.h"
/* passing in an already filled in node (item) */
void Queue::enqueue(Node* node) {
node->next = nullptr;
if(isEmpty()) {
front = rear = node;
} else {
rear->next = node;
rear = node;
}
}
void Queue::dequeue() {
if(isEmpty()) {
std::cout << "No items in stock.";
return;
}
if(front == rear) {
Node* last = front;
front = rear = nullptr;
delete last;
}
else {
Node* temp = front;
front = front->next;
delete temp;
}
}
void Queue::display() {
if(isEmpty())
std::cout << "No items in stock.";
else {
Node* curr = front;
while(curr != nullptr) {
std::cout << "ID: " << curr->id << std::endl;
std::cout << "Name: " << curr->name << std::endl;
std::cout << "Category: " << curr->category << std::endl;
std::cout << "Quantity: " << curr->quantity << std::endl;
std::cout << "Price: " << curr->price << std::endl;
std::cout << "Date In: " << curr->dateIn << std::endl;
std::cout << "Date Out: " << curr->dateOut << std::endl;
curr = curr->next;
}
}
}
Node* Queue::peek() {
if(!isEmpty()) {
return front;
}
return nullptr;
}
bool Queue::isEmpty() {
return front == nullptr;
}