Hi all, the last test case of ‘Create a Priority Queue Class’ is not passing; I checked the order in my terminal, it is perfectly working. may be I missing something from question itself; Help needed!
function PriorityQueue () {
this.collection = [];
this.printCollection = function() {
console.log(this.collection);
};
var qSize = 0;
this.priorities = [];
this.size = function(){
return qSize;
}
this.isEmpty = function(){
return (qSize == 0);
}
this.enqueue = function(elem, priority){
if(this.size() == 0){
this.collection[qSize] = elem;
this.priorities[qSize] = priority;
qSize++;
return;
}
for(var i=0; i<qSize; i++){
if(this.priorities[i] > priority){
this.collection.splice(i, 0, elem);
this.priorities.splice(i, 0, priority);
qSize++;
return;
}
}
this.collection[this.collection.length] = elem;
this.priorities[this.priorities.length] = priority;
qSize++;
return;
}
this.dequeue = function(){
if(this.isEmpty())
return;
var temp = this.collection[qSize];
var temp1 = this.priorities[qSize];
qSize--;
return temp;
}
}