using System.Collections.Generic;
public static int FindNetworkEndpoint(int startingNode, int[] fromIds, int[] toIds)
if((toIds.Length<= 0)||(toIds.Length > 10000))
List<int> toIdsList = toIds.ToList();
List<int> fromIdsList = fromIds.ToList();
int indexNode = int.MinValue;
int oldIndex = int.MinValue;
while (!endFound && !lapEnded)
if (!startSearch && (node == startingNode))
if(fromIdsList.Contains(node))
indexNode = fromIdsList.IndexOf(node);
node = toIdsList[indexNode];
public static void Main()
int[] fromIds = new int[] { 4, 9, 6, 1 };
int[] toIds = new int[] { 9, 5, 1, 4 };
Console.WriteLine(startNodeId);
for (int i = 0; i < n; i++)
Console.WriteLine("from : " + fromIds[i] + " -> " + toIds[i]);
int endPointId = FindNetworkEndpoint(startNodeId, fromIds, toIds);
Console.WriteLine("L'ID du dernier noeud : "+endPointId.ToString());