function PriortyQueue(){
function QueueElement(element,priorty){
this.element = element
this.priorty = priorty
}
this.items = []
PriortyQueue.prototype.enqueue = function (element,priorty) {
let queueElement = new QueueElement(element,priorty)
if(this.items.length === 0) {
this.items.push(queueElement)
} else {
let added = false
for(let i = 0; i < this.items.length; i++){
if(queueElement.priorty < this.items[i].priorty) {
this.items.splice(i,0,queueElement)
added = true
break
}
}
if (!added) {
this.items.push(queueElement)
}
}
}
PriortyQueue.prototype.dequeue = function(){
return this.items.shift()
}
PriortyQueue.prototype.front = function(){
return this.items[0]
}
PriortyQueue.prototype.isEmpty = function(){
return this.items.length === 0
}
PriortyQueue.prototype.size = function(){
return this.items.length
}
PriortyQueue.prototype.toString = function(){
let resultString = ''
for(let i = 0; i < this.items.length; i++){
resultString = this.items[i] + ''
}
return resultString
}
}
let q = new PriortyQueue()
q.enqueue('a',11)
q.enqueue('b',2)
q.enqueue('c',50)
console.log(q)