#include<iostream>
using namespace std;
#include<stack>
#include<exception>
template <typename T>class CQueue{
public:
CQueue(void);
~CQueue(void);
void appendTail(const T& node);
T deleteHead();
private:
stack<T> s1;
stack<T> s2;
};
template<typename T> CQueue<T>::CQueue(void){
}
template<typename T> CQueue<T>::~CQueue(void){
}
template<typename T> void CQueue<T>::appendTail(const T& node){
s1.push(node);
}
template<typename T> T CQueue<T>::deleteHead(){
if(s2.size()<=0){
while(!s1.empty()){
T& data=s1.top();
s1.pop();
s2.push(data);
}
}
if(s2.size()==0)
throw new exception("queue is empty!");
T& head=s2.top();
s2.pop();
return head;
}
#include"CQueue.h";
void main(){
CQueue<char> queue;
queue.appendTail('a');
queue.appendTail('b');
queue.appendTail('c');
char head=queue.deleteHead();
cout<<head<<endl;
head=queue.deleteHead();
cout<<head<<endl;
queue.appendTail('d');
head=queue.deleteHead();
cout<<head<<endl;
head=queue.deleteHead();
cout<<head<<endl;
}