Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 532 Bytes

9.md

File metadata and controls

33 lines (26 loc) · 532 Bytes

队列是一种线性数据结构,先进先出(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()