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
#include <iostream>
using namespace std;
 
class MyIntStack {
    int p[10];
    int tos;
public:
    MyIntStack() { tos = 0; }
    bool push(int n);
    bool pop(int &n);
};
 
bool MyIntStack::push(int n) {
    if (tos != 10) {
        p[n] = n;
        tos++;
        return true;
    }
    else {
        return false;
    }
}
 
bool MyIntStack::pop(int &n) {
    if (tos != 0) {
        tos--;
        n = p[tos];
        return true;
    }
    else return false;
}
 
int main() {
    MyIntStack a;
    for (int i = 0; i < 11; i++) {
        if (a.push(i)) cout << i << ' ';
        else cout << endl << i + 1 << " 번째 stack full" << endl;
    }
    int n;
    for (int i = 0; i < 11; i++) {
        if (a.pop(n)) cout << n << ' ';
        else cout << endl << i + 1 << " 번째 stack empty";
    }
    cout << endl;
}
cs


+ Recent posts