示例#1
0
        public static Graph <string> GetTestStructure()
        {
            var graph = new Graph <string>();

            graph.AddNode("Privacy.htm");
            graph.AddNode("People.aspx");
            graph.AddNode("About.htm");
            graph.AddNode("Index.htm");
            graph.AddNode("Products.aspx");
            graph.AddNode("Contact.aspx");

            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("People.aspx"), (GraphNode <string>)graph.Nodes.FindByValue("Privacy.htm"), 0);

            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("Privacy.htm"), (GraphNode <string>)graph.Nodes.FindByValue("Index.htm"), 0);
            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("Privacy.htm"), (GraphNode <string>)graph.Nodes.FindByValue("About.htm"), 0);

            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("About.htm"), (GraphNode <string>)graph.Nodes.FindByValue("Privacy.htm"), 0);
            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("About.htm"), (GraphNode <string>)graph.Nodes.FindByValue("People.aspx"), 0);
            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("About.htm"), (GraphNode <string>)graph.Nodes.FindByValue("Contact.aspx"), 0);

            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("Index.htm"), (GraphNode <string>)graph.Nodes.FindByValue("About.htm"), 0);
            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("Index.htm"), (GraphNode <string>)graph.Nodes.FindByValue("Contact.aspx"), 0);
            graph.AddDirectedEdge((GraphNode <string>)graph.Nodes.FindByValue("Index.htm"), (GraphNode <string>)graph.Nodes.FindByValue("Products.aspx"), 0);
            //web.AddDirectedEdge((GraphNode<string>)web.Nodes.FindByValue("Products.aspx" }, web.Nodes.FindByValue("Index.htm" }, 0);
            //web.AddDirectedEdge((GraphNode<string>)web.Nodes.FindByValue("Products.aspx" }, web.Nodes.FindByValue("People.aspx" }, 0);

            return(graph);
        }
示例#2
0
        public void DoShortestPathBBB16()
        {
            var graph = new Graph();

            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            graph.AddVertex(4);
            graph.AddVertex(5);
            graph.AddVertex(6);
            graph.AddVertex(7);
            graph.AddVertex(8);
            graph.AddVertex(9);
            graph.AddDirectedEdge(1, 2);
            graph.AddDirectedEdge(2, 3);
            graph.AddDirectedEdge(3, 4);
            graph.AddDirectedEdge(4, 1);
            graph.AddDirectedEdge(4, 5);
            graph.AddDirectedEdge(5, 1);
            graph.AddDirectedEdge(3, 6);
            graph.AddDirectedEdge(6, 7);
            graph.AddDirectedEdge(7, 4);
            graph.AddDirectedEdge(6, 8);
            graph.AddDirectedEdge(8, 9);
            var path = LeetcodeApp.GetShortestPath(graph, 3, 1);
        }