Code:
void Graph::printPath( const Vertex & dest ) const
{
string m;
if( dest.prev != NULL )
{
vector<Edge> e = (dest.prev)->adj;
for(unsigned int i = 0; i< e.size(); i++)
{
Edge edge = e[i];
if( edge.dest == &dest)
{
m = (*edge.movieTitle).title();
break;
}
}
printPath( *dest.prev );
cout << " was in " << m << " with ";
cout << ((*data)[(dest.a)]).name() << endl;
cout << ((*data)[(dest.a)]).name();
}
else
{
cout << ((*data)[(dest.a)]).name();
}
}
I have this function and currently with the input I give it the output is:
Damon, Matt was in Saving Private Ryan with Hanks, Tom
Hanks, Tom was in Apollo 13 with Harris, Ed
Harris, Ed
It is displaying the final name an extra time. I want the output to just be:
Damon, Matt was in Saving Private Ryan with Hanks, Tom
Hanks, Tom was in Apollo 13 with Harris, Ed
Anyone know how I can fix this?