class CQueue {
public:
stack<int> s1;
stack<int> s2;
CQueue() {
while(!s1.empty()){
s1.pop();
}
while(!s2.empty()){
s2.pop();
}
}
void appendTail(int value) {
s1.push(value);
}
int deleteHead() {
if(!s2.empty()){
}
else{
if(s1.empty())
return -1;
while(!s1.empty()){
s2.push(s1.top());
s1.pop();
}
}
int re=s2.top();
s2.pop();
return re;
}
};
/**
* Your CQueue object will be instantiated and called as such:
* CQueue* obj = new CQueue();
* obj->appendTail(value);
* int param_2 = obj->deleteHead();
*/
相关文章
- 11-18poj 2828 buy Tickets 用线段树模拟带插入的队列
- 11-18c++练习10——两个栈实现一个队列
- 11-18leetcode---用队列实现栈
- 11-18栈————用队列实现栈
- 11-18225. 用队列实现栈
- 11-18LeetCode 232.用栈实现队列
- 11-18LeetCode刷题之路-每日一题-232. 用栈实现队列
- 11-18用2个栈实现队列
- 11-18232.用栈实现队列
- 11-18【剑指Offer-09】用两个栈实现队列