File tree 1 file changed +3
-0
lines changed
src/graphs/breadthfirstsearch
1 file changed +3
-0
lines changed Original file line number Diff line number Diff line change @@ -36,13 +36,15 @@ public static List<Vertex> bfs(Vertex vertex) {
36
36
List <Vertex > vertexList = new ArrayList <>();
37
37
if (vertex != null ) {
38
38
vertex .setVisited (true );
39
+ System .out .println (vertex );
39
40
queue .add (vertex );
40
41
while (!queue .isEmpty ()) {
41
42
Vertex currentVertex = queue .remove ();
42
43
Vertex unvisitedVertex ;
43
44
vertexList .add (currentVertex );
44
45
while ((unvisitedVertex = getUnvisitedVertex (currentVertex )) != null ) {
45
46
unvisitedVertex .setVisited (true );
47
+ System .out .println (unvisitedVertex );
46
48
queue .add (unvisitedVertex );
47
49
}
48
50
}
@@ -53,6 +55,7 @@ public static List<Vertex> bfs(Vertex vertex) {
53
55
private static Vertex getUnvisitedVertex (Vertex vertex ) {
54
56
for (Vertex temp : vertex .getDependsOn ()) {
55
57
if (!temp .isVisited ()) {
58
+ vertex .getDependsOn ().remove (temp );
56
59
return temp ;
57
60
}
58
61
}
You can’t perform that action at this time.
0 commit comments