Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typo in Dijkstra's priority queue comparison function breaks Dijkstra #15

Open
@cxcorp

Description

When creating the min priority queue, the Dijkstra function passes in return cost1, cost2 as the function, causing it to always return cost2:

this.pq = new jss.IndexMinPQ(V, function(cost1, cost2){
return cost1, cost2;
});

It should probably be cost1 - cost2, like:

diff --git a/src/jsgraphs.js b/src/jsgraphs.js
index 5409240..1392673 100644
--- a/src/jsgraphs.js
+++ b/src/jsgraphs.js
@@ -936,7 +936,7 @@ var jsgraphs = jsgraphs || {};
 this.edgeTo = [];
 this.cost = [];
 this.pq = new jss.IndexMinPQ(V, function(cost1, cost2){
- return cost1, cost2;
+ return cost1 - cost2;
 });
 
 for(var v =0; v < V; ++v){

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /