#include <iostream>
using namespace std;
/**Stack**/
class Node
{
private:
int data;
Node* sptr;
Node* top;
public:
Node()
{
top = 0;
}
void push(int _data)
{
Node* current = new Node;
current->data = _data;
current->sptr = 0;
if(isEmpty())
{
top = current;
}
else
{
current->sptr = top;
top = current;
}
}
void pop()
{
if(isEmpty())
{
cout<<"stack empty"<<endl;
}
else
{
Node* current = top;
top = top->sptr;
cout<<current->data<<endl;
delete current;
}
}
bool isEmpty()
{
if(top==0)
return true;
else
return false;
}
void show()
{
Node* current=0;
cout<<"**stack: ";
for(current=top;current!=0;current = current->sptr)
{
cout<<current->data<<" ";
}
cout<<endl;
}
};
int main()
{
Node myStack;
int n,m;
cout<<"*key 1 is push, key 0 is pop*"<<endl;
while(cin>>n)
{
if(n)
{
cin>>m;
myStack.push(m);
}
else
{
myStack.pop();
}
myStack.show();
}
return 0;
}