//用两个栈实现队列
class Queue{
constructor(queue, size) {
this.queue = queue || [];
this.size = size || Infinity;
this.inputStack = this.queue;
this.outputStack = []
}
push(value) {
this.inputStack.push(value)
}
pop() {
if(!this.outputStack.length) {
if(!this.inputStack.length) return console.log('当前队列为空');
while(this.inputStack.length) {
this.outputStack.push(this.inputStack.pop())
}
}
return this.outputStack.pop()
}
}
const myQueue = new Queue([2,3,4,5])
console.log(myQueue.pop())
console.log(myQueue.pop())
myQueue.push(54)
let num = myQueue.pop();
while(num) {
console.log(num)
num = myQueue.pop()
}
console