队列是一种线性数据结构,先进先出(FIFO), 队列的出口叫对头, 队列的入口叫队尾。
var MyQueue = function() {
this.arr = []
return this
}
MyQueue.prototype.push = function (num) {
this.arr.push(num)
}
MyQueue.prototype.deQueue = function () {
this.arr.splice(0, 1)
}
MyQueue.prototype.output = function () {
for(let i=0; i<this.arr.length; i++) {
console.log(this.arr[i]);
}
}
var obj = new MyQueue()
obj.push(1)
obj.push(3)
obj.push(76)
obj.deQueue()
obj.output()