-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActionStack.h
74 lines (65 loc) · 1.01 KB
/
ActionStack.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
#pragma once
#include "DEFS.h";
template<typename Element>
class ActionStack
{
private:
static const int size = 100;
Element stack[size];
int index = 0;
public:
ActionStack();
void push(Element);
Element pop();
void clear();
bool isFull();
bool isEmpty();
};
template<typename Element>
ActionStack<Element>::ActionStack()
{
clear();
}
template<typename Element>
void ActionStack<Element>::push(Element act)
{
if (isFull())
{
for (int i = 0; i < size - 1; i++)
stack[i] = stack[i + 1];
stack[size - 1] = act;
}
else
{
stack[index++] = act;
}
}
template<typename Element>
Element ActionStack<Element>::pop()
{
if (isEmpty())
return stack[0];
else
return stack[--index];
}
template<typename Element>
void ActionStack<Element>::clear()
{
index = 0;
}
template<typename Element>
bool ActionStack<Element>::isFull()
{
if (index == size)
return true;
else
return false;
}
template<typename Element>
bool ActionStack<Element>::isEmpty()
{
if (index == 0)
return true;
else
return false;
}