Exemplo n.º 1
0
        static void DoGraphTestAsInt()
        {
            var g = new Graph <int>(0, 1, 2, 3);

            g.AddEdge(0, 1);
            g.AddEdge(0, 2);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            g.AddEdge(2, 3);
            g.AddEdge(3, 3);

            var searchAlgorithm = new DepthFirstSearch <int>();
            var result          = searchAlgorithm.DoSearch(g, 2);

            Console.WriteLine($"DepthFirstSearch On a graph int: {result}");
        }
Exemplo n.º 2
0
        static void DoGraphTestAsStrings()
        {
            var g = new Graph <string>("A", "B", "C", "D", "E", "F");

            g.AddEdge("A", "B");
            g.AddEdge("A", "C");
            g.AddEdge("A", "D");
            g.AddEdge("B", "A");
            g.AddEdge("B", "C");
            g.AddEdge("B", "D");
            g.AddEdge("C", "E");
            g.AddEdge("D", "E");
            g.AddEdge("E", "F");
            g.AddEdge("F", "F");

            var searchAlgorithm = new DepthFirstSearch <string>();
            var result          = searchAlgorithm.DoSearch(g, "A");

            Console.WriteLine($"DepthFirstSearch on a Graph of string: {result}");
        }