#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
class Stack{
int *p;
int index=-1;
public:
Stack(){
p = new int [10];
}
Stack &operator<<(int k){
this->p[++index] = k;
return *this;
}
void operator>>(int &k){ //pop
k=this->p[index];
this->index--;
}
bool operator!(){
if(this->index==-1) return true;
else return false;
}
};
int main() {
Stack stack;
stack << 3 << 5 << 10;
while (true) {
if(!stack) break;
int x;
stack >> x;
cout << x << ' ';
}
cout << endl;
return 0;
}
'C++' 카테고리의 다른 글
[C++] 명품 C++ 프로그래밍 실습문제 8장 오픈챌린지/openchallenge (0) | 2023.01.13 |
---|---|
[C++] 명품 C++ 프로그래밍 실습문제 7장 12번 (0) | 2023.01.11 |
[C++] 명품 C++ 프로그래밍 실습문제 7장 10번 (0) | 2023.01.11 |
[C++] 명품 C++ 프로그래밍 실습문제 7장 9번 (0) | 2023.01.11 |
[C++] 명품 C++ 프로그래밍 실습문제 7장 8번 (0) | 2023.01.11 |