class Queue {
constructor () {
this.inputStack = []
this.outputStack = []
}
enqueue (item) {
this.inputStack.push(item)
}
dequeue (item) {
this.outputStack = []
if (this.inputStack.length > 0) {
while (this.inputStack.length > 0) {
this.outputStack.push(this.inputStack.pop())
}
}
if (this.outputStack.length > 0) {
console.log(this.outputStack.pop())
this.inputStack = []
while (this.outputStack.length > 0) {
this.inputStack.push(this.outputStack.pop())
}
}
}
listIn () {
let i = 0
while (i < this.inputStack.length) {
console.log(this.inputStack[i])
i++
}
}
listOut () {
let i = 0
while (i < this.outputStack.length) {
console.log(this.outputStack[i])
i++
}
}
}
const queue = new Queue()
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(8)
queue.enqueue(9)
console.log(queue.dequeue())
console.log(queue.dequeue())