#include <iostream>
using namespace std;
class MyIntStack
{
int* p;
int size;
int tos;
public:
MyIntStack() {};
MyIntStack(int size);
MyIntStack(MyIntStack& s);
~MyIntStack();
bool Push(int n);
bool Pop(int& n);
};
int main() {
MyIntStack a(10);
a.Push(10);
a.Push(20);
MyIntStack b = a;
b.Push(30);
int n;
a.Pop(n);
cout << "스택 a에서 팝한 값 " << n << endl;
b.Pop(n);
cout << "스택 b에서 팝한 값 " << n << endl;
}
bool MyIntStack::Push(int n) {
tos++;
if (tos == 10)
return false;
else
{
p[tos] = n;
return true;
}
}
bool MyIntStack::Pop(int& n) {
tos--;
if (tos == -1)
return false;
else {
n = p[tos];
return true;
}
}
MyIntStack::MyIntStack(int size) {
tos = -1;
p = new int[size];
this->size = size;
}
MyIntStack::MyIntStack(MyIntStack& s) {
this->p = new int[s.size];
this->size = s.size;
this->tos = s.tos;
for (int i = 0; i <= s.tos; i++)
this->p[i] = s.p[i];
}
MyIntStack::~MyIntStack()
{
delete[]p;
}