队列结构
- 只允许在前端进行删除操作,在后端插入操作
- 先进先出
FIFO
enqueue 向队列尾部添加
dequeue 移除队列的第一个并返回被移除的元素
front 返回第一个元素,但是不删除它
isEmpty
size
toString
function Queue() {
this.items = []
Queue.prototype.enqueue = function (e) {
this.items.push(e)
}
Queue.prototype.dequeue = function () {
return this.items.shift()
}
Queue.prototype.front = function () {
return this.items[0]
}
Queue.prototype.isEmpty = function () {
return this.items.length == 0
}
Queue.prototype.size = function () {
return this.items.length
}
Queue.prototype.toString = function () {
var str = ''
for (var i = 0; i < this.items.length; i++) {
str += this.items[i] + ' '
}
return str
}
}
var q = new Queue()
q.enqueue('djp')
q.enqueue('wzc')
q.enqueue('lwc')
console.log(q.isEmpty())