-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaekjoon10828.cpp
84 lines (75 loc) · 1.12 KB
/
baekjoon10828.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
using namespace std;
int N, input;
string S;
int arr[10001];
class arr_stack {
public:
int top_index;
int MAX_SIZE;
// int* arr;
arr_stack(int size) {
top_index = -1;
MAX_SIZE = size;
//arr = new int[size];
}
int empty() {
if (top_index == -1)
return 1;
else
return 0;
}
int size() {
return top_index + 1;
}
void push(int data) {
/*if (size() == MAX_SIZE) {
return 0;
}
else {
top_index += 1;
arr[top_index] = data;
}*/
top_index += 1;
arr[top_index] = data;
}
int pop() {
if (empty())
return -1;
else {
int temp = arr[top_index];
top_index -= 1;
return temp;
}
}
int top() {
if (empty())
return -1;
else
return arr[top_index];
}
};
int main() {
arr_stack s(10001);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S;
if (S == "push") {
cin >> input;
s.push(input);
}
else if (S == "pop") {
cout << s.pop() << endl;
}
else if (S == "size") {
cout << s.size() << endl;
}
else if (S == "empty") {
cout << s.empty() << endl;
}
else if (S == "top") {
cout << s.top() << endl;
}
}
return 0;
}