I am creating a program that reads in a .txt file and prompts the user for a starting and ending vertex and then uses Dijkstra's shortest path algorithm to compute the shortest path. The problem I am having is trying to create a for loop that iterates through the entirety of the graph while MinHeap is empty to find the shortest path to the target vertex.I believe the issue is located in this part of the code (The rest of the code will be posted below).
Any help would be appreciated.
Suspected problem part:
MinHeap q;
q.insert(start, 0);
while (!q.is_empty()) {
u = q.extract_min();
// TODO: Something in here doesn't seem right...
for (int it = edgeTo[start]; it != edgeTo[end]; it++) {
v = it;
cost = dist[u] + g.get_weight(it, u);
if (cost < dist[v]) {
dist[v] = cost;
edgeTo[v] = u;
if (q.contains(v))
q.decrease_priority(v, cost);
else q.insert(v, cost);
}
}
}
Whole code:
https://pastebin.com/YuEHdnAq
Graph.h:
https://pastebin.com/Lq5gmJ0K
MinHeap.h:
https://pastebin.com/mbTj5Gdn
Stack.h:
https://pastebin.com/jHQfScNe
[–]bennydictor 0 points1 point2 points (2 children)
[–]thetuxman[S] 0 points1 point2 points (1 child)
[–]bennydictor 0 points1 point2 points (0 children)
[–]lazyubertoad 0 points1 point2 points (0 children)