You are on a course about graphs, so you should "know" the usual approaches: depth first, etc. That leaves two tasks: (1) choose suitable approach and (2) implement it correctly.
Side note:
If each node has unique name, then
1 2
|
for ( const auto & jack : nodes ) {
if ( jack.name == start ) {
|
is technically correct, but logically misleading. Preferably:
1 2
|
1. Find node X that is the starting point
2. Get routes for X
|
1 2 3 4
|
auto node = std::find_if( nodes.begin(), nodes.end(), [start](auto& n){return start == n.name;} );
if ( node != nodes.end() ) {
// determine routes from *node
}
|
You do output within the search. In the second example you probably get:
ACBACBDB
If you would print newline when limit is reached, then you would get:
ACBACB
DB
Perhaps you should store the route and show it when you hit the limit? Not before.
Note that whenever you reach a crossroads, you have to
make a copy of the "route so far" for each path that you will follow.