function Queue() {
this.dataStore = []
this.enqueue = enqueue
this.dequeue = dequeue
this.front = front
this.back = back
this.toString = toString
this.empty = empty
}
function enqueue(element) {
this.dataStore.push(element)
}
function dequeue() {
return this.dataStore.shift()
}
function front() {
return this.dataStore[0]
}
function back() {
return this.dataStore[this.dataStore.length - 1]
}
function toString() {
var str = ''
for (var i = 0; i < this.dataStore.length; i++) {
str += this.dataStore[i]
}
return str
}
function empty() {
if(this.dataStore.length == 0) {
return true
}
return false
}
var q = new Queue()
q.enqueue('aaa')
q.enqueue('bbb')
q.enqueue('ccc')
console.log(q.toString())
q.dequeue()
console.log(q.toString())
console.log(q.front())
console.log(q.back())
队列
最新推荐文章于 2024-09-16 19:03:50 发布