首页 > 其他 > 详细

数据结构_队列

时间:2020-02-18 12:52:46      阅读:44      评论:0      收藏:0      [点我收藏+]
//队列,先进先出

  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
    }
  }

 

数据结构_队列

原文:https://www.cnblogs.com/JunLan/p/12325499.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!