Click here to Skip to main content
15,895,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a dijkstra algorithm for weighted, undirected graph. How can I rearrange it in order to calculate weighted and directed graph's shortest path?
Posted
Updated 19-May-11 5:07am
v2

1 solution

You have more than enough information on this well-known algorithm to implement it in C++. See http://en.wikipedia.org/wiki/Dijkstra's_algorithm[^].

Now, this article does not mention arc weights. You can easily modify the algorithm if you need to take it into account. Look at the distance calculation in the pseudocode (see dist, dist_between). When you calculate them, multiply each arc's distance with its weight, that's all you need.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900