コード例 #1
0
 public static bool FindNextLeg(Route[] returnArray, int count, City destination, City currentCity)
 {
     for (int i = 0; i < currentCity.Connections.Length; i++)
     {
         if (CanContinueSearch(returnArray, currentCity.Connections[i].GetCity()))
         {
             if (count == returnArray.Length)
             {
                 throw new Exception("No Valid Route Found");
             }
             returnArray[count] = currentCity.Connections[i];
             if(currentCity.Connections[i].GetCity().Equals(destination))
             {
                 return true;
             }
             else
             {
                 if(FindNextLeg(returnArray, count + 1, destination, currentCity.Connections[i].GetCity()))
                 {
                     return true;
                 }
             }
         }
     }
     return true;
 }
コード例 #2
0
 public static int FindNextLegDistance(Route[] returnArray, int count, City destination, City currentCity)
 {
     for (int i = 0; i < currentCity.Connections.Length; i++)
     {
         if (CanContinueSearch(returnArray, currentCity.Connections[i].GetCity()))
         {
             if (currentCity.Connections[i].GetCity().Equals(destination))
             {
                 return returnArray[count].GetDays();
             }
             else
             {
                 if (FindNextLeg(returnArray, count + 1, destination, returnArray[i].GetCity()))
                 {
                     return returnArray[count].GetDays() + FindNextLegDistance(returnArray, count + 1, destination, currentCity.Connections[i].GetCity());
                 }
             }
         }
     }
     return 0;
 }
コード例 #3
0
 private static bool CanContinueSearch(Route[] returnArray, City city)
 {
     for (int i = 0; i < returnArray.Length; i++)
     {
         if (returnArray[i].GetCity().Equals(city.GetCityName()))
         {
             return false;
         }
     }
     return true;
 }