当前位置: 首页>>代码示例>>C#>>正文


C# Graph.BreadthFirstTraversal方法代码示例

本文整理汇总了C#中Graph.BreadthFirstTraversal方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.BreadthFirstTraversal方法的具体用法?C# Graph.BreadthFirstTraversal怎么用?C# Graph.BreadthFirstTraversal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.BreadthFirstTraversal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Directed

        public void Directed()
        {
            var graph = new Graph<int>(true);
            var vertex1 = new Vertex<int>(1);
            var vertex2 = new Vertex<int>(2);
            var vertex3 = new Vertex<int>(3);
            var vertex4 = new Vertex<int>(4);
            var vertex5 = new Vertex<int>(5);
            var vertex6 = new Vertex<int>(6);
            var vertex7 = new Vertex<int>(7);

            graph.AddVertex(vertex1);
            graph.AddVertex(vertex2);
            graph.AddVertex(vertex3);
            graph.AddVertex(vertex4);
            graph.AddVertex(vertex5);
            graph.AddVertex(vertex6);
            graph.AddVertex(vertex7);

            graph.AddEdge(vertex1, vertex2);
            graph.AddEdge(vertex1, vertex3);
            graph.AddEdge(vertex1, vertex5);
            graph.AddEdge(vertex5, vertex3);

            graph.AddEdge(vertex3, vertex6);
            graph.AddEdge(vertex3, vertex4);
            graph.AddEdge(vertex2, vertex7);

            var trackingVisitor = new TrackingVisitor<Vertex<int>>();

            graph.BreadthFirstTraversal(trackingVisitor, vertex1);

            Assert.AreEqual(trackingVisitor.TrackingList.Count, graph.Vertices.Count);

            Assert.AreEqual(trackingVisitor.TrackingList[0].Data, 1);
            Assert.AreEqual(trackingVisitor.TrackingList[1].Data, 2);
            Assert.AreEqual(trackingVisitor.TrackingList[2].Data, 3);
            Assert.AreEqual(trackingVisitor.TrackingList[3].Data, 5);
            Assert.AreEqual(trackingVisitor.TrackingList[4].Data, 7);
            Assert.AreEqual(trackingVisitor.TrackingList[5].Data, 6);
            Assert.AreEqual(trackingVisitor.TrackingList[6].Data, 4);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:42,代码来源:BreadthFirstTraversal.cs

示例2: BreadthFirstTraversalExample

        public void BreadthFirstTraversalExample()
        {
            // Initialize a new graph instance
            var graph = new Graph<int>(true);

            // Add three vertices to the graph
            var vertex1 = graph.AddVertex(1);
            var vertex2 = graph.AddVertex(2);
            var vertex3 = graph.AddVertex(3);

            // Add edges between the vertices
            graph.AddEdge(vertex1, vertex2);
            graph.AddEdge(vertex2, vertex3);
            graph.AddEdge(vertex1, vertex3);

            // Create a counting visitor.  The counting
            // visitor will keep track of the number of
            // items on which Accept was called.
            var visitor = new CountingVisitor<Vertex<int>>();

            // Perform a breadth first traversal of the graph,
            // starting at vertex vertex1.
            graph.BreadthFirstTraversal(visitor, vertex1);

            // The visitor will have visited three vertices.
            Assert.AreEqual(visitor.Count, 3);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:27,代码来源:GraphExamples.cs

示例3: ExceptionNullVisitor

 public void ExceptionNullVisitor()
 {
     var graph = new Graph<int>(true);
     graph.BreadthFirstTraversal(null, new Vertex<int>(4));
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:5,代码来源:BreadthFirstTraversal.cs

示例4: ExceptionNullVertex

 public void ExceptionNullVertex()
 {
     var graph = new Graph<int>(true);
     graph.BreadthFirstTraversal(new TrackingVisitor<Vertex<int>>(), null);
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:5,代码来源:BreadthFirstTraversal.cs


注:本文中的Graph.BreadthFirstTraversal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。