#include<iostream>
#include<stack>
using namespace std;
template<class T> class myQueue
{
public:
void In(T node);
T Out();
private:
stack<T> stack1;
stack<T> stack2;
};
template<class T> void myQueue<T>::In(T node)
{
stack1.push(node);
}
template<class T> T myQueue<T>::Out()
{
if(stack2.size()<=0)
{
while (stack1.size()>0)
{
T &data = stack1.top();
stack1.pop();
stack2.push(data);
}
}
if(stack2.size()<=0)
{
throw new exception("qeue is empty");
}
T head = stack2.top();
stack2.pop();
return head;
}
void main()
{
myQueue<int> myQ;
myQ.In(1);
myQ.In(2);
myQ.In(3);
cout<<myQ.Out()<<endl;
cout<<myQ.Out()<<endl;
cout<<myQ.Out()<<endl;
system("pause");
}