예제 #1
0
        private static void Graph()
        {
            Graph graph = new Graph(9);

            graph.AddEdge(0, 1, 4);
            graph.AddEdge(1, 2, 8);
            graph.AddEdge(2, 3, 7);
            graph.AddEdge(3, 4, 9);
            graph.AddEdge(4, 5, 10);
            graph.AddEdge(5, 6, 2);
            graph.AddEdge(6, 7, 1);
            graph.AddEdge(7, 0, 8);
            graph.AddEdge(1, 7, 11);
            graph.AddEdge(7, 8, 7);
            graph.AddEdge(6, 8, 6);
            graph.AddEdge(5, 2, 4);
            graph.AddEdge(5, 3, 14);
            graph.AddEdge(8, 2, 2);

            graph.PrintGraph();

            GraphTopics gt = new GraphTopics();

            gt.FindShortestPath(graph, 0, 4);
            gt.FindShortestPath(graph, 0, 8);
            gt.FindShortestPath(graph, 3, 4);
            gt.FindShortestPath(graph, 8, 5);
        }
예제 #2
0
        private static void MatrixShortestPath()
        {
            try
            {
                int[,] mat = new int[, ]
                {
                    { 2, 1, 5, 1 },
                    { 3, 4, 2, 2 },
                    { 1, 2, 3, 3 },
                    { 1, 3, 2, 4 }
                };

                GraphTopics gt = new GraphTopics();

                //gt.MatrixUniquePaths(mat, 4, 4);

                gt.MatrixUniquePathsIterative(mat, 4, 4);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }