Пример #1
0
 public static void InsightDFS(int vertex, bool[] used, AdjacencyMatrix graph)
 {
     used[vertex] = true;
     for (int i = 0; i < graph.NumberVertexes; i++)
         if (graph.GetWeigth(vertex, i) != Constants.NotConnected && !used[i])
         {
             used[i] = true;
             InsightDFS(i, used, graph);
         }
     used[vertex] = true;
 }
Пример #2
0
 public static bool BFS(AdjacencyMatrix graph, int vertex1, int vertex2)
 {
     Queue<int> queue = new Queue<int>();
     int numberVertexes = graph.NumberVertexes;
     queue.Enqueue(vertex1);
     while (queue.Count != 0)
     {
         int vertex = queue.Dequeue();
         for (int i = 0; i < numberVertexes; i++)
             if (graph.GetWeigth(vertex, i) != Constants.NotConnected)
             {
                 if (i == vertex2)
                 {
                     return true;
                 }
                 queue.Enqueue(i);
             }
     }
     return false;
 }