Created
October 8, 2019 05:10
-
-
Save kingsleytan/933a7e28c237a1f4a5a3b720739b3fd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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