Skip to content

Commit ea95cde

Browse files
committed
Fix a bug in the index min pq
1 parent 65c426b commit ea95cde

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Algorithms/DataStructures/Queue/IndexMinPQ.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void DecreaseKey(int index, T item)
9292

9393
public bool Contains(int index)
9494
{
95-
return qp[index] == -1;
95+
return qp[index] != -1;
9696
}
9797

9898
private void Sink(int k)

Algorithms/Graphs/MST/EagerPrim.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private void Visit(WeightedGraph G, int v)
4040
int w = e.other(v);
4141
if (!marked[w])
4242
{
43-
if (pq.Contains(w))
43+
if (!pq.Contains(w))
4444
{
4545
pq.Insert(w, e);
4646
}

AlgorithmsUnitTest/Graphs/ShortestPaths/DijkstraUnitTest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ public void Test()
2424
Dijkstra dijkstra = new Dijkstra(G, 0);
2525
for(var v=1; v < G.V(); ++v)
2626
{
27-
if (!dijkstra.HasPathTo(v)) continue;
27+
if (!dijkstra.HasPathTo(v))
28+
{
29+
Console.WriteLine("Path not found for {0}", v);
30+
continue;
31+
}
2832
IEnumerable<Edge> path = dijkstra.PathTo(v);
2933

3034
console.WriteLine(ToString(path));
35+
Console.WriteLine(ToString(path));
3136
}
3237
}
3338

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy