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
#include <iostream>
using namespace std;
 
class Statistics {
    int *stack;
    int index;
public:
    Statistics() { stack = new int[100]; index = 0; }
    ~Statistics() { delete[]stack; }
    Statistics& operator<<(int x);
    bool operator!();
    void operator>> (int &x);
};
 
Statistics& Statistics::operator<<(int x) {
    stack[index] = x;
    index++;
    return *this;
}
 
bool Statistics::operator!() {
    if (index == 0return true;
    else return false;
}
 
void Statistics::operator>>(int &x) {
    x = stack[index - 1];
    index--;
}
 
int main() {
    Statistics stack;
    stack << 3 << 5 << 10;
    while (true) {
        if (!stackbreak;
        int x;
        stack >> x;
        cout << x << ' ';
    }
    cout << '\n';
}
cs


+ Recent posts