Advertisement
shikdernyc

Untitled

Apr 19th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. bool RouteMap::isRoute(City *origin, City *destionation)
  2. {
  3. std::stack<City *> cities;
  4. cities.push(origin);
  5. while (!cities.empty())
  6. {
  7. City *current = cities.top();
  8. cities.pop();
  9.  
  10. current->setHasBeenVisited(true);
  11.  
  12. if (current == destionation)
  13. {
  14. return true;
  15. }
  16.  
  17. std::vector<City *> children = current->getNeighbors();
  18. if (children.empty())
  19. {
  20. cities.pop();
  21. }
  22. else
  23. {
  24. for (City *city : children)
  25. {
  26. if (!city->hasBeenVisited())
  27. {
  28. cities.push(city);
  29. break;
  30. }
  31. }
  32. }
  33. }
  34.  
  35. return false;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement