![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/79df70ab8fb61a1145c0299a5206684f.png)
这个题目比较简单,看题解就可以
class CQueue {
stack<int>stack1,stack2;
public:
CQueue() {
while(!stack1.empty())
{
stack1.pop();
}
while(!stack2.empty())
{
stack2.pop();
}
}
void appendTail(int value) {
stack1.push(value);
}
int deleteHead() {
if(stack2.empty())
{
while(!stack1.empty())
{
stack2.push(stack1.top());
stack1.pop();
}
}
if(stack2.empty())
{
return -1;
}
else
{
int deleteHead=stack2.top();
stack2.pop();
return deleteHead;
}
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/