Beispiel #1
0
        public static void Main()
        {
            int[,] graph = new int[, ] {
                { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
                { 4, 0, 8, 0, 0, 0, 0, 11, 0 },
                { 0, 8, 0, 7, 0, 4, 0, 0, 2 },
                { 0, 0, 7, 0, 9, 14, 0, 0, 0 },
                { 0, 0, 0, 9, 0, 10, 0, 0, 0 },
                { 0, 0, 4, 14, 10, 0, 2, 0, 0 },
                { 0, 0, 0, 0, 0, 2, 0, 1, 6 },
                { 8, 11, 0, 0, 0, 0, 1, 0, 7 },
                { 0, 0, 2, 0, 0, 0, 6, 7, 0 }
            };
            GFG t = new GFG();

            t.dijkstra(graph, 0);
            Console.ReadKey();
        }
Beispiel #2
0
        // Driver Code
        public static void Main()
        {
            /* Let us create the example
             * graph discussed above */
            int[,] graph = new int[, ] {
                { 0, 4, 0, 0, 0, 0, 0, 8, 0 },
                { 4, 0, 8, 0, 0, 0, 0, 11, 0 },
                { 0, 8, 0, 7, 0, 4, 0, 0, 2 },
                { 0, 0, 7, 0, 9, 14, 0, 0, 0 },
                { 0, 0, 0, 9, 0, 10, 0, 0, 0 },
                { 0, 0, 4, 14, 10, 0, 2, 0, 0 },
                { 0, 0, 0, 0, 0, 2, 0, 1, 6 },
                { 8, 11, 0, 0, 0, 0, 1, 0, 7 },
                { 0, 0, 2, 0, 0, 0, 6, 7, 0 }
            };

            GFG t = new GFG();

            t.dijkstra(graph, 0);
        }
        static void Main(string[] args)
        {
            /* Let us create the example
             * graph discussed above */
            //int[][] graph = {
            //    new [] {0, 4, 0, 0, 0, 0, 0, 8, 0},
            //    new [] {4, 0, 8, 0, 0, 0, 0, 11, 0},
            //    new [] {0, 8, 0, 7, 0, 4, 0, 0, 2},
            //    new [] {0, 0, 7, 0, 9, 14, 0, 0, 0},
            //    new [] {0, 0, 0, 9, 0, 10, 0, 0, 0},
            //    new [] {0, 0, 4, 14, 10, 0, 2, 0, 0},
            //    new [] {0, 0, 0, 0, 0, 2, 0, 1, 6},
            //    new [] {8, 11, 0, 0, 0, 0, 1, 0, 7},
            //    new [] {0, 0, 2, 0, 0, 0, 6, 7, 0}};

            int[][] graphDef =
            {
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
            };

            graphDef[0][1] = 4;
            graphDef[0][7] = 8;

            graphDef[1][0] = 4;
            graphDef[1][2] = 8;
            graphDef[1][7] = 11;

            graphDef[2][1] = 8;
            graphDef[2][3] = 7;
            graphDef[2][5] = 4;
            graphDef[2][8] = 2;

            graphDef[3][2] = 7;
            graphDef[3][4] = 9;
            graphDef[3][5] = 14;

            graphDef[4][3] = 9;
            graphDef[4][5] = 10;

            graphDef[5][2] = 4;
            graphDef[5][3] = 14;
            graphDef[5][4] = 10;

            graphDef[6][7] = 1;
            graphDef[6][8] = 6;

            graphDef[7][8] = 7;

            graphDef[8][2] = 2;
            graphDef[8][6] = 6;
            graphDef[8][7] = 7;

            var cfg = new GFG();

            cfg.Dijkstra(graphDef, 0);


            var graph    = new Graph(graphDef);
            var dijkstra = graph.Dijkstra(0);
        }