logo CodeStepByStep logo

isReachable

Language/Type: C++ graphs collections
Related Links:
Author: Marty Stepp (on 2016/06/16)

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
Type your C++ solution code here:


This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.