I’m am writing a code to find the shortest distance between two points. My code is working perfect till now. I mean it finds the distance and the path that they should pass. I need to print this information, but I should make a print function. The way it works is something like that: For example initial point is 4 and final is 13.
I should come up with an algorithm that check their intermediate points. Let’s say between 4 & 13 there is point : 7
4–7–13 Now I need to check every point between them like:
4–6–7–9–13 To be more specific it will check if there is a point between 4-6 and 6-7 and 7-9 and 9-13. So next in the next iteration it may be formed another list like:
4–2–6–7–5–9–17–13 Now let’s say that there will not be any intermediate value between them. And that is what I should print. I really would appreciate any help, suggestion that you may give to me
The Warshall-Floyd algorithm (used by the OP), has a version which is able to determine the path in addition to the distance between nodes of a graph:
Floyd-Warshall algorithm with path-reconstruction
However, it must be noted that this is not the best possible algorithm to solve the shortest-path problem.