using namespace std;
class Stack
{
private:
int maxSize;
int top;
int theArray[100];
public:
Stack(int capacity)
{
maxSize = capacity;
top = -1;
int x;
cin>>x;
int i = 0;
while(x != 0)
{
theArray[++top] = x;
cin>>x;
}
}
bool isEmpty()
{
return top == -1;
}
bool isFull()
{
return top == maxSize - 1;
}
void push(int x)
{
if(isFull())
cout<<"push failed,the stack is full"<<endl;
else
{
theArray[++top] = x;
}
}
void pop()
{
if(isEmpty())
cout<<"pop failed,the stack is empty"<<endl;
else
{
top--;
}
}
int topAndPop()
{
if(isEmpty())
cout<<"top and pop failed,the stack is empty"<<endl;
else
{
return theArray[top - 1];
top--;
}
}
int Top()
{
if(isEmpty())
cout<<"top failed,the stack is empty"<<endl;
else
return theArray[top];
}
void outputStack()
{
if(isEmpty())
cout<<"output failed,the stack is empty"<<endl;
else
{
for(int i = 0;i <= top;i ++)
{
cout<<theArray[i]<<" ";
}
}
}
};