用两个栈实现一个队列
/*
*/
class CQueue {
public:
stack<int> in_s;
stack<int> out_s;
CQueue() {
}
void appendTail(int value) {
in_s.push(value);
}
int deleteHead() {
if(out_s.size()==0 && in_s.size()==0)
{
return -1;
}
if(out_s.size()==0)
{
while(in_s.size())
{
int temp=in_s.top();
out_s.push(temp);
in_s.pop();
}
int temp=out_s.top();
out_s.pop();
return temp;
}
int temp=out_s.top();
out_s.pop();
return temp;
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/