题目:
用两个栈实现队列的push和Pop操作
思路:先进先出,实现两个函数。
两个栈inStack,outStack,实现转移
const inStack = [];
const outStack = [];
function push(node){
inStack.push(node);
}
function pop(node){
if(outStack.length){
return outStack.pop();
}
else{
while(inStack.length){
outStack.push(inStack.pop());
}
return outStack.pop();
}
}