Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- public static void PrintPath(int[] path)
- {
- int i = 0;
- while (path[i] > 0)
- {
- Console.Write(path[i] + " ");
- i++;
- }
- }
- public static int[] BuildPath(int[,] arr, int firstSelection, int station, int call)
- {
- int nextStation = 0;
- int countPath = 0;
- int[] path = new int[arr.GetLength(0)];
- for (int i = 0; i < path.Length; i++)
- path[i] = -1;
- path[0] = station + 1;
- path[1] = arr[station, firstSelection];
- countPath = 2;
- while (countPath < path.Length && path[countPath - 1] != call + 1)
- {
- nextStation = arr[path[countPath - 1] - 1, 0];
- if (nextStation == path[countPath - 2])
- nextStation = arr[path[countPath - 1] - 1, 1];
- path[countPath] = nextStation;
- countPath++;
- }
- return path;
- }
- public static void IndirectCommunication(int[,] arr, int station, int call)
- {
- int[] pathOne, pathTwo;
- pathOne = BuildPath(arr, 0, station, call);
- pathTwo = BuildPath(arr, 1, station, call);
- Console.WriteLine("\nPath one");
- PrintPath(pathOne);
- Console.WriteLine("\nPath two");
- PrintPath(pathTwo);
- Console.WriteLine();
- }
- public static bool DirectCommunication(int[,] arr, int station, int call)
- {
- return call - 1 == arr[station, 0] || call - 1 == arr[station, 1];
- }
- public static void Main(string[] args)
- {
- int[,] channels = new int[16, 2] {{5, 9}, {7, 10}, {6, 11}, {13, 16}, {1, 16}, {3, 11},
- {2, 15}, {12, 14}, {1, 14}, {2, 15}, {3, 6}, {8, 13},
- {4, 12}, {8, 9}, {7, 10}, {4, 5} };
- for (int i = 0; i < channels.GetLength(0); i++)
- {
- Console.Write("Station number " + (i + 1) +" - ");
- Console.Write(channels[i, 0] + " , " + channels[i, 1]);
- Console.WriteLine();
- }
- IndirectCommunication(channels, 4, 12);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement