Pathfinding

Project: Allow the user to put cities on a map and connect them. Also allow the user to input two cities, and output the shortest path between them.

Technique

For each city, store its connections to other cities. To find the shortest path, recursively travel down each connection and keep track of the traveled distance. This is called graph traversal. It is very important that you keep track of which cities have already been visited, otherwise, the function will never terminate.
Last section Next section