-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyStack.h
80 lines (63 loc) · 1.08 KB
/
myStack.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "Stack.h"
template <class T>
class myStack :public Stack<T>
{
public:
T top()
{
if (!isEmpty())
{
return Stack<T>::arr[Stack<T>::currentSize - 1];
}
else
{
cout << "Stack is EMPTY, returning a junk value" << endl;
return 0;
}
}
bool isFull()
{
if (Stack<T>::currentSize == Stack<T>::maxSize)
return true;
return false;
}
bool isEmpty()
{
if (Stack<T>::currentSize == 0)
return true;
return false;
}
myStack(int s) :Stack<T>(s)
{
}
T pop()
{
if (!isEmpty())
{
Stack<T>::currentSize--;
return Stack<T>::arr[Stack<T>::currentSize];
}
else
{
cout << "Stack is EMPTY, returning a junk value" << endl;
return 0;
}
}
void push(T value)
{
if (!isFull())
Stack<T>::arr[Stack<T>::currentSize++] = value;
else
cout << "Stack is FULL" << endl;
}
void display()
{
cout << "Max Size: " << Stack<T>::maxSize << endl;
cout << "Current Size: " << Stack<T>::currentSize << endl;
for (int i = 0; i < Stack<T>::currentSize; i++)
{
cout << i << ". " << Stack<T>::arr[i] << endl;
}
}
};