Exemple #1
0
        private static void CyclicGraph2()
        {
            Graph1 <char> Cyclic = new Graph1 <char>();

            Console.WriteLine("Cyclic Graph");
            Cyclic.AddEdge('A', 'B', false);
            Cyclic.AddEdge('B', 'C', false);
            Cyclic.AddEdge('C', 'A', false);
            Cyclic.AddEdge('D', 'C', false);

            Console.Write("Is it cyclic? ");

            var i = Cyclic.IsCyclic();

            if (i)
            {
                Console.Write("Yes.");
            }
            else
            {
                Console.Write("No.");
            }

            Console.WriteLine("\nLast Line");
            Console.ReadLine();
        }
Exemple #2
0
        private static void FindPathBetweenTwoNodes()
        {
            Graph1 <int> Graph = new Graph1 <int>();

            Graph.AddEdge(1, 2, false);
            Graph.AddEdge(2, 3, false);
            Graph.AddEdge(3, 4, false);
            Graph.AddEdge(1, 5, false);
            Graph.AddEdge(5, 6, false);
            Graph.AddEdge(6, 7, false);
            Graph.AddEdge(5, 8, false);
            Graph.AddEdge(1, 9, false);
            Graph.AddEdge(9, 10, false);

            Graph.FindPathBetweenTwoVertices(1, 7);
            Console.ReadLine();
        }
Exemple #3
0
        private static void TremauxExecution()
        {
            Graph1 <char> Tremaux = new Graph1 <char>();

            Tremaux.AddEdge('A', 'B', true);
            Tremaux.AddEdge('A', 'C', true);
            Tremaux.AddEdge('A', 'E', true);
            Tremaux.AddEdge('B', 'D', true);
            Tremaux.AddEdge('B', 'F', true);
            Tremaux.AddEdge('C', 'G', true);
            Tremaux.AddEdge('E', 'F', true);

            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("Printing Whole Graph:\n" + Tremaux.ToString());
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");

            Console.WriteLine("\n**** DFS iterative ****\n");
            Tremaux.DFS('A');
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("\n**** DFS recursive ****\n");
            Tremaux.DFS('A', true);
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("\n**** BFS ****\n");
            Tremaux.BFS('A');
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("\n**** Spanning Tree ****\n");
            Tremaux.FindSpanningTree();
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.Write("Is it cyclic? ");
            var i = Tremaux.IsCyclic();

            if (i)
            {
                Console.Write("Yes.");
            }
            else
            {
                Console.Write("No.");
            }
            Console.WriteLine("\nLast Line");
            Console.ReadLine();
        }
Exemple #4
0
        private static void GermanCities()
        {
            Graph1 <string> germanCities = new Graph1 <string>();

            germanCities.AddEdge("Frankfurt", "Mannheim", false);
            germanCities.AddEdge("Frankfurt", "Wurzburg", false);
            germanCities.AddEdge("Frankfurt", "Kassel", false);
            germanCities.AddEdge("Mannheim", "Karlsruhe", false);
            germanCities.AddEdge("Karlsruhe", "Augsburg", false);
            germanCities.AddEdge("Augsburg", "Munchen", false);
            germanCities.AddEdge("Wurzburg", "Erfurt", false);
            germanCities.AddEdge("Wurzburg", "Nurnberg", false);
            germanCities.AddEdge("Nurnberg", "Stuttgart", false);
            germanCities.AddEdge("Nurnberg", "Munchen", false);
            germanCities.AddEdge("Kassel", "Munchen", false);

            Console.WriteLine("\n**** DFS Iterative *****");
            germanCities.DFS("Frankfurt");
            Console.WriteLine("--------------");
            Console.WriteLine("\n**** DFS Recursive ****\n");
            germanCities.DFS("Frankfurt", true);
            Console.WriteLine("**************");
            Console.WriteLine();
            Console.WriteLine("**** BFS *****");
            germanCities.BFS("Frankfurt");
            Console.WriteLine("**************");
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~");
            germanCities.FindSpanningTree();
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~");
            germanCities.FindPathBetweenTwoVertices("Frankfurt", "Stuttgart");

            Console.ReadLine();
        }