7.3.3 Application: Connecting Cities

7.5.3 Application: Connecting Cities

In this example, you are going to take a look at a real-life graph example. This graph represents a hypothetical airline route map any you want to figure out how to get from one city to another with the least amount of connections.

Did we mention this was real-life 80 years ago? This route map doesnโ€™t use a traditional hub network that airlines often use today, but it does do a good job illustrating how a graph can be used.

As mentioned before, graphs often contain a lot of data. Even this relatively simple route map has dozens of connections, so the graph will be loaded using a function, but this time the function is reading from a file.

You will notice that there are several helper functions. While these may be a little different than the last example, you should notice that the city struct and the shortestPath function are essentially the same as the previous example.

Take time to explore this example. Try changing the connections to different cities to see the path.

Last updated