本文整理汇总了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);
}
示例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);
}
示例3: ExceptionNullVisitor
public void ExceptionNullVisitor()
{
var graph = new Graph<int>(true);
graph.BreadthFirstTraversal(null, new Vertex<int>(4));
}
示例4: ExceptionNullVertex
public void ExceptionNullVertex()
{
var graph = new Graph<int>(true);
graph.BreadthFirstTraversal(new TrackingVisitor<Vertex<int>>(), null);
}