/*
*@brief: 使用兩個棧完成隊列的先入先出
* 思路:棧1只是進新數,棧2爲空的時候,將棧1的數據push
* 到stack2中去,再從棧2進行pop
*/
class solution{
public:
void push(int node){
stack1.push(node);
}
int pop(){
if(stack2.empty()){
while(!stack1.empty()){
int tmp=stack1.top();
stack1.pop();
stack2.push(tmp);
}
int ret=stack2.top();
stack2.pop();
return ret;
}else{
int ret=stack2.top();
stack2.pop();
return ret;
}
}
stack<int> stack1;
stack<int> stack2;
};