Skip to content

Commit d4bcb7d

Browse files
author
techpanja
committed
Adding print statements to bfs.
1 parent c08727a commit d4bcb7d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/graphs/breadthfirstsearch/BFS.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ public static List<Vertex> bfs(Vertex vertex) {
3636
List<Vertex> vertexList = new ArrayList<>();
3737
if (vertex != null) {
3838
vertex.setVisited(true);
39+
System.out.println(vertex);
3940
queue.add(vertex);
4041
while (!queue.isEmpty()) {
4142
Vertex currentVertex = queue.remove();
4243
Vertex unvisitedVertex;
4344
vertexList.add(currentVertex);
4445
while ((unvisitedVertex = getUnvisitedVertex(currentVertex)) != null) {
4546
unvisitedVertex.setVisited(true);
47+
System.out.println(unvisitedVertex);
4648
queue.add(unvisitedVertex);
4749
}
4850
}
@@ -53,6 +55,7 @@ public static List<Vertex> bfs(Vertex vertex) {
5355
private static Vertex getUnvisitedVertex(Vertex vertex) {
5456
for (Vertex temp : vertex.getDependsOn()) {
5557
if (!temp.isVisited()) {
58+
vertex.getDependsOn().remove(temp);
5659
return temp;
5760
}
5861
}

0 commit comments

Comments
 (0)