Update PriorityQueue.js

Changed the default priority to value of the item in the add() method.
This commit is contained in:
PradeepG-07 2023-09-15 19:44:26 +05:30 committed by GitHub
parent 76617fa83a
commit 587648a11e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,7 +22,7 @@ export default class PriorityQueue extends MinHeap {
* @param {number} [priority] - items priority. * @param {number} [priority] - items priority.
* @return {PriorityQueue} * @return {PriorityQueue}
*/ */
add(item, priority = 0) { add(item, priority = item) {
this.priorities.set(item, priority); this.priorities.set(item, priority);
super.add(item); super.add(item);
return this; return this;