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 |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 5장 7번 (0) | 2018.05.09 |
|---|---|
| 명품 C++ Programming 실습문제 5장 6번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 4번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 3번 (0) | 2018.05.09 |
| 명품 C++ Programming 실습문제 5장 2번 (0) | 2018.05.09 |