Ejemplo n.º 1
0
        static void DoGraphThingies()
        {
            int    graphNum = 2;
            Graph1 g        = CreateGraph(graphNum);

            g.PrintGraph();

            bool recursive = true;

            g.DFSTraversal("b", recursive);
            g.DFSTraversal("c", recursive);

            g.DFSTraversal("a", recursive);
            g.DFSTraversal("a", !recursive);

            g.BFSTraversal("a");
        }
Ejemplo n.º 2
0
        static Graph1 CreateGraph(int graphNum)
        {
            Graph1 g = new Graph1();

            if (graphNum == 1)
            {
                g.AddEdge("a", "b");
                g.AddEdge("b", "c");
                g.AddEdge("b", "d");
                g.AddEdge("d", "c");
                g.AddEdge("d", "c");
                g.AddEdge("c", "a");
            }
            else if (graphNum == 2)
            {
                g.AddEdge("a", "b");
                g.AddEdge("b", "c");
                g.AddEdge("c", "d");
                g.AddEdge("d", "d1");
                g.AddEdge("d1", "d2");
                g.AddEdge("c", "c1");
                g.AddEdge("c1", "c2");
            }
            else if (graphNum == 3)                     // this one is essentially a binary tree
            {
                g.AddEdge("a", "b");
                g.AddEdge("a", "c");
                g.AddEdge("b", "d");
                g.AddEdge("b", "e");
                g.AddEdge("c", "f");
                g.AddEdge("c", "g");
                g.AddEdge("d", "h");
                g.AddEdge("d", "i");
            }
            else
            {
                g.AddEdge("a", "b");
                g.AddEdge("a", "c");
            }
            return(g);
        }