1: // Created by Frank M. Carrano and Timothy M. Henry. 2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. 4: /** Tests whether a sequence of flights exists between two cities. 5: @pre originCity and destinationCity both exist in the flight map. 6: @post Cities visited during the search are marked as visited 7: in the flight map. 8: @param originCity The origin city. 9: @param destinationCity The destination city. 10: @return True if a sequence of flights exists from originCity 11: to destinationCity; otherwise returns false. */ 12: bool Map::isPath(City originCity, City destinationCity) 13: { 14: // Mark the current city as visited 15: markVisited(originCity); 16: 17: bool foundDestination = (originCity == destinationCity); 18: if (!foundDestination) 19: { 20: // Try a flight to each unvisited city 21: City nextCity = getNextCity(originCity); 22: while (!foundDestination && (nextCity != NO_CITY)) 23: { 24: foundDestination = isPath(nextCity, destinationCity); 25: if (!foundDestination) 26: nextCity = getNextCity(originCity); 27: } // end while 28: } // end if 29: return foundDestination; 30: } // end isPath