-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.cpp
55 lines (42 loc) · 815 Bytes
/
5.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
#include <iostream>
using namespace std;
struct st{
private:
int top;
int * a;
public:
st(int n){
top = -1;
a = new int{};
}
int getTop(){
if ( top == -1) return -1;
return a[top];
}
void push(int x){
top++;
a[top] = x;
}
void pop(){
if (top != -1){
top--;
}
}
int clear(){
top = -1;
cout <<"ok"<<endl;
}
};
int main(){
int d[] = {1,5,61,56,2,4};
int n = sizeof(d) / sizeof(int);
st s(n);
for (int i = 0; i < n; i++){
s.push(d[i]);
}
for (int i = 0; i < n; i++){
cout<<s.getTop()<<endl;
s.pop();
}
return 0;
}