언어/C++
7장 10번 - 스택 구현하기
옥돌소녀
2019. 11. 28. 14:01
#include <iostream>
using namespace std;
class Stack {
int stack[10];
int top;
public :
Stack() { top=-1; }
Stack& operator <<(int n) {
top++;
stack[top] = n;
return *this;
}
Stack operator >>(int &n) {
n = stack[top];
top--;
return *this;
}
bool operator !() {
if( top == -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;
}