Skip to content

Commit fe7e8f0

Browse files
author
rpanjrath
committed
Trees: PrintNaryTreeWithLevels minor refactoring.
1 parent 6c9fba7 commit fe7e8f0

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/trees/leftviewofatree/LeftViewOfATree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void bfs(Graph graph) {
2323
vertex.setVisited(true);
2424
System.out.println(vertex);
2525
queue.add(vertex);
26-
//null acts as a pointer/marker when new level should begin.
26+
//dummy acts as a pointer/marker when new level should begin.
2727
Vertex dummy = new Vertex("dummy");
2828
queue.add(dummy);
2929
while (!queue.isEmpty()) {

src/trees/printnarytreewithlevels/PrintNaryTreeWithLevels.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ public static void bfs(Graph graph) {
3131
System.out.println(vertex + "level " + counter);
3232
counter++;
3333
queue.add(vertex);
34-
//null acts as a pointer/marker when new level should begin.
35-
queue.add(null);
34+
//dummy acts as a pointer/marker when new level should begin.
35+
Vertex dummy = new Vertex("dummy");
36+
queue.add(dummy);
3637
while (!queue.isEmpty()) {
3738
Vertex currentVertex = queue.remove();
38-
if (currentVertex == null) {
39+
if (currentVertex == dummy) {
3940
counter++;
4041
if (queue.isEmpty()) {
4142
break;
4243
}
4344
currentVertex = queue.remove();
44-
queue.add(null);
45+
queue.add(dummy);
4546
}
4647
Vertex unvisitedVertex;
4748
while ((unvisitedVertex = getUnvisitedVertex(currentVertex)) != null) {

0 commit comments

Comments
 (0)