<script>
//数组实现
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 reslutstring=' '
for(var i=0;i<this.items.length;i++){}
reslutstring=this.items[i]+" "
}
}
</script>
与栈的初始化类似,其中只有加入队列与删除队列的操作与栈的操作不同