logo CodeStepByStep logo

isReachable

Language/Type: C++ graphs collections
Related Links:

Write a function named isReachable that accepts three parameters: a reference to a BasicGraph, and two strings representing names of vertexes v1 and v2. Your function should return true if a path can be made from the vertex v1 to the vertex v2, or false if not. For example, in the graph below, vertex F is reachable from A by the path {A, B, E, F}, but H is not reachable from A. If the two vertexes are the same, return true. You may assume that the parameter values passed are valid.

A --> B <-- C
|     |     ^
|     |     |
V     V     |
D <-- E --> F
|     ^     ^
|     |     |
V     |     |
G <-- H <-- I
Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.