#include<iostream>
#include <deque>
using namespace std;
template<class T>
class Mystack
{
public:
Mystack(){}
~Mystack(){}
void push(T &t);
T top();
void pop();
private:
deque<T> A;
deque<T> B;
};
template<class T>
void Mystack<T>::push(T &t)
{
A.push_back(t);
}
template<class T>
T Mystack<T>::top()
{
while(A.size()>1)
{
B.push_back(A.front());
A.pop_front();
}
T tmp=A.front();
B.push_back(A.front());
A.pop_front();
while(B.size()!=0)
{
A.push_back(B.front());
B.pop_front();
}
return tmp;
}
template<class T>
void Mystack<T>::pop()
{
while(A.size()>1)
{
B.push_back(A.front());
A.pop_front();
}
A.pop_front();
while(B.size()!=0)
{
A.push_back(B.front());
B.pop_front();
}
}
void main()
{
Mystack<int> a;
for(int i=0;i<10;i++)
a.push(i);
for(i=0;i<10;i++)
{
cout<<a.top()<<endl;
a.pop();
}
}