Example #1
0
File: Bfs.cs Project: Farga83/Algs4
 public Bfs(Graph graph, int root)
 {
     if (graph == null) {
         throw new ArgumentNullException("graph");
     }
     this.marked = new bool[graph.Vertices()];
     this.edgeTo = Enumerable.Repeat(-1, graph.Vertices()).ToArray();
     this.distTo = Enumerable.Repeat(-1, graph.Vertices()).ToArray();
     this.count = 0;
     this.root = root;
     this.BreadthFirstSearch(graph, root);
 }
Example #2
0
 public void UndirectedCreateIsCorrectlyBuilt()
 {
     var input = CreateTestInput();
     var g = new Graph(GraphType.Undirected, input, 7);
     Assert.AreEqual(7, g.Vertices());
     Assert.AreEqual(10, g.Edges());
     Assert.AreEqual(3, g.Adjacent(0).Count);
     Assert.AreEqual(1, g.Adjacent(1).Count);
     Assert.AreEqual(2, g.Adjacent(2).Count);
     Assert.AreEqual(1, g.Adjacent(3).Count);
     Assert.AreEqual(0, g.Adjacent(4).Count);
     Assert.AreEqual(2, g.Adjacent(5).Count);
     Assert.AreEqual(1, g.Adjacent(6).Count);
 }