Skip to content

Commit

Permalink
Removed redundant BFS vertices
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasmusson committed Dec 24, 2020
1 parent 22c61e0 commit be62f0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/main/java/algorithms/graphs/BFS/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ void BFS(int s) {

// Mark the current node as visited and enqueue it
visited[s] = true;
System.out.println("Starting at " + s);
System.out.println("n " + s);
queue.add(s);

while (queue.size() != 0) {
// Dequeue a vertex from queue and print it
s = queue.poll();
System.out.println("De-queueing " + s);
// System.out.print(s + " ");

// Get all adjacent vertices of the de-queued vertex s
// If a adjacent has not been visited, then mark it
Expand All @@ -45,7 +43,7 @@ void BFS(int s) {
int n = i.next();
if (!visited[n]) {
visited[n] = true;
System.out.println("Queueing " + n);
System.out.println("n " + n);
queue.add(n);
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/test/java/algorithms/graphs/BFS/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@ public void SetUp() {
public void BreadFirstSearch() {

g.addEdge(0, 1);
g.addEdge(1, 0);
g.addEdge(1, 4);
g.addEdge(4, 1);
g.addEdge(4, 6);
g.addEdge(6, 4);
g.addEdge(6, 0);
g.addEdge(0, 6);
g.addEdge(1, 5);
g.addEdge(5, 1);
g.addEdge(5, 3);
g.addEdge(3, 5);
g.addEdge(3, 0);
g.addEdge(0, 3);
g.addEdge(5, 2);
g.addEdge(2, 5);
g.addEdge(2, 7);
g.addEdge(7, 2);

System.out.println("Following is Breadth First Traversal "+
"(starting from vertex 0)");
Expand Down

0 comments on commit be62f0d

Please sign in to comment.