1.用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
push加入节点,pop全部弹出 let inStack = []; let outStack = []; function push(node) { inStack.push(node) } function pop() { if(outStack.length == 0){ while(inStack.length != 0){ outStack.push(inStack.pop()); }
}
return outStack.pop();
} module.exports = { push : push, pop : pop };