Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool RouteMap::isRoute(City *origin, City *destionation)
- {
- std::stack<City *> cities;
- cities.push(origin);
- while (!cities.empty())
- {
- City *current = cities.top();
- cities.pop();
- current->setHasBeenVisited(true);
- if (current == destionation)
- {
- return true;
- }
- std::vector<City *> children = current->getNeighbors();
- if (children.empty())
- {
- cities.pop();
- }
- else
- {
- for (City *city : children)
- {
- if (!city->hasBeenVisited())
- {
- cities.push(city);
- break;
- }
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement