// 队列 规则 先进先出
//利用js的数组来实现
function Queue () {
this.items = []
// 入队列
Queue.prototype.enQueue = function(element) {
this.items.push(element)
return this.items.length
}
// 出队列
Queue.prototype.deQueue = function () {
var element = this.items.shift()
return element
}
// 队列的第一个元素
Queue.prototype.front = function () {
return this.items[0]
}
//队列的元素个数
Queue.prototype.size = function () {
return this.items.length
}
// 队列是否为空
Queue.prototype.isEmpty = function () {
return this.items.length == 0
}
// 队列的内容转化为字符串
Queue.prototype.toString = function () {
var str = ''
for(var i = 0; i < this.items.length; i++) {
str += this.items[i] + ' '
}
return str
}
}