-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTellerQueue.cpp
64 lines (53 loc) · 1.03 KB
/
TellerQueue.cpp
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
60
61
62
63
/*
* TelleQueue.cpp
*
* Created on: Oct 6, 2018
* Author: nwalzer
*/
#include <iostream>
#include "TellerQueue.h"
TellerQueue::TellerQueue() {
head = NULL;
length = 0;
}
TellerQueue::~TellerQueue() {
Node *nxt = head;
while (nxt) {
Node* toDel = nxt;
nxt = nxt->next;
delete toDel;
}
}
/**Adds a customer to the end of the line
* @param cust The customer to add
* @return void
*/
void TellerQueue::pushCust(Customer* cust) {
length++;
Node* newCust = new Node();
newCust->cust = cust;
if(head == NULL){
head = newCust;
return;
} //if head is null, newCust is head
Node *nxt = head;
while (nxt->next) {//while the next isn't NULL
nxt = nxt->next;
}
nxt->next = newCust;
}
/**Removes and Returns the first customer in the line
* @return The first customer in the line
*/
Customer* TellerQueue::popCust(){
length--;
Node* toPop = head;
head = head->next;
return toPop->cust;
}
/**Gets the length of the queue
* @return The length of the queue
*/
int TellerQueue::giveLength(){
return length;
}