数据结构_队列

//队列,先进先出

  class Queue {
    constructor () {
      this.items = []
    }
    //入队
    enqueue (elem) {
      return this.items.push(this.items)
    }
    //出队
    dequeue () {
      return this.items.shift()
    }
    //查看队首元素
    front () {
      return this.items[0]
    }
    //是否为空
    isEmpty () {
      return this.items.length <= 0
    }
    //清空队列
    clear () {
      this.items = []
      return true
    }
    //队列长度
    size () {
      return this.items.length
    }
  }

 

posted @ 2020-02-18 11:48  前端之旅  阅读(127)  评论(0)    收藏  举报