function PriorityQueue() {
function QueueElement() {
this.element = element
this.priority = priority
}
this.items = []
PriorityQueue.prototype.enqueue = function() {
let queueElement = new QueueElement(element, priority)
if (this.items.length === 0) {
this.items.push(queueElement)
} else {
let added = false
for(let i = 0; i < this.items.length; i++) {
if (queueElement.priority < this.items[i]) {
this.items.splice(i, 0,queueElement)
added = true
break
}
}
if(!added) {
this.items.push(queueElent)
}
}
}
PriorityQueue.prototype.dequeue = function() {
return this.items.shift()
}
PriorityQueue.prototype.front = function() {
return this.items[0]
}
PriorityQueue.prototype.isEmpty = function() {
return this.items.length === 0
}
PriorityQueue.prototype.size = function() {
return this.items.length
}
PriorityQueue.prototype.toString = function() {
return this.items.join(' ')
}
}