-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.cpp
57 lines (55 loc) · 1.12 KB
/
stack.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
//
// Created by Abdelrahman Wael on 3/27/2022.
//
#include "stack.h"
#include <iostream>
#include "customer.h"
#include "Time.h"
#include <string>
using namespace std;
bool timeEquality(Time time1, Time time2);
stack::stack(){
size = 100;
top = -1;
list = new customer[size];
}
stack::stack(int size){
this -> size = size;
top = -1;
list = new customer[size];
}
bool stack::isEmpty(){
return top == -1;
}
bool stack::isFull(){
return top == (size - 1);
}
customer stack::peak(){
if (isEmpty()) {
cout << "The stack is empty" << endl;
return customer();
}
return list[top];
}
customer stack::pop(){
if (isEmpty()){
cout << "The stack is empty" << endl;
return customer();
}
return list[top--];
}
void stack::push(customer customer){
if (isFull()){
cout << "The stack is full" << endl;
return;
}
list[++top] = customer;
}
customer stack::getCustomer(Time time) {
for (int i = 0; i < size; i++){
if(timeEquality(list[i].getArrivalTime(), time)){
return list[i];
}
}
return customer();
}