Skip to content

Instantly share code, notes, and snippets.

@kingsleytan
Created October 8, 2019 05:10
Show Gist options
  • Save kingsleytan/933a7e28c237a1f4a5a3b720739b3fd3 to your computer and use it in GitHub Desktop.
Save kingsleytan/933a7e28c237a1f4a5a3b720739b3fd3 to your computer and use it in GitHub Desktop.
function PriorityQueue() {
...
this.enqueue = function (element) {
if (this.isEmpty()) {
collection.push(element);
} else {
var added = false;
for (var i = 0; i < collection.length; i++) {
if (element[1] < collection[i][1]) {
collection.splice(i, 0, element);
added = true;
break;
}
}
if (!added) {
collection.push(element);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment