#include <iostream>
#include<exception>
#include<stdlib.h>
#include <stdexcept>
#include<stack>
using namespace std;
template<typename T>class CQueue //定义队列声明
{
public:
CQueue(void);
~CQueue(void);
void appendTail(const T&node);
T deleteHead();
private:
stack<T> stack1;
stack<T> stack2;
};

template<typename T>void CQueue<T>::appendTail(const T&element){   //将元素存入栈1中
stack1.push(element);
}

//具体实现为用其中一个栈来存取数据,然后将该栈中的内容弹出到栈2中,这样栈2中存储的数据就是顺序数据,从而可以实现模拟队列

//另外还可以用两个队列来实现模拟栈,具体实现为将元素加入队列1后,将前面的n-1个元素先加入到队列2中再弹出第n个元素,这样就实现了后入先出的栈操作

template<typename T>T CQueue<T>::deleteHead(){   //删除进入队列的第一个节点
if(stack2.size()<=0){
while(stack1.size()>0){
T & data=stack1.top();
stack1.pop();
stack2.push(data);
}
}
if(stack2.size()==0){
logic_error ex = ("queue is empty");
throw new exception(ex);
}
T head = stack2.top();
stack2.pop();
return head;
}