00001
00027 bool Map::isPath(int originCity, int destinationCity)
00028 {
00029 Stack aStack;
00030 int topCity, nextCity;
00031 bool success;
00032
00033 unvisitAll();
00034
00035
00036 try
00037 { aStack.push(originCity);
00038 markVisited(originCity);
00039
00040 aStack.getTop(topCity);
00041 while (!aStack.isEmpty() && (topCity != destinationCity))
00042 {
00043
00044
00045
00046
00047
00048 success = getNextCity(topCity, nextCity);
00049
00050 if (!success)
00051 aStack.pop();
00052
00053 else
00054 { aStack.push(nextCity);
00055 markVisited(nextCity);
00056 }
00057
00058 if(!aStack.isEmpty())
00059 aStack.getTop(topCity);
00060 }
00061
00062 if (aStack.isEmpty())
00063 return false;
00064 else
00065 return true;
00066 }
00067 catch (StackException e)
00068 { cout << e.what() << endl;
00069 }
00070 }