-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyStack.h
73 lines (58 loc) · 960 Bytes
/
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
//
// Created by FanBig on 2023/3/19.
//
#ifndef EVALUATEEXPRESSION_NODE_MYSTACK_H
#define EVALUATEEXPRESSION_NODE_MYSTACK_H
/*
MyStack_h
*/
#ifndef MyStack_h
#define MyStack_h
#include <cstddef>
template<class T>
class MyStack {
public:
T arr[100];
int topIndex;
MyStack() {
topIndex = 0;
}
bool isEmpty() {
return topIndex == 0;
}
void push(T n) {
arr[topIndex] = n;
topIndex++;
}
T pop() {
if (isEmpty()) {
return NULL;
}
topIndex--;
return arr[topIndex];
}
T top() {
if (isEmpty()) {
return NULL;
}
return arr[topIndex - 1];
}
};
#endif
//template<class T>
//class MyStack {
//public:
// T arr[100];
// int topIndex;
//
// MyStack();
//
// bool isEmpty();
//
// void push(T n);
//
// T pop();
//
// T top();
//};
#endif //EVALUATEEXPRESSION_NODE_MYSTACK_H