Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9cae15e

Browse files
updates tree printer class
1 parent 01ab000 commit 9cae15e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/TreePrinter.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public interface PrintableNode {
2828
* tree root node
2929
*/
3030
public static void print(PrintableNode root) {
31-
List<List<String>> lines = new ArrayList<List<String>>();
31+
List<List<String>> lines = new ArrayList<>();
3232

33-
List<PrintableNode> level = new ArrayList<PrintableNode>();
34-
List<PrintableNode> next = new ArrayList<PrintableNode>();
33+
List<PrintableNode> level = new ArrayList<>();
34+
List<PrintableNode> next = new ArrayList<>();
3535

3636
level.add(root);
3737
int nn = 1;
@@ -86,7 +86,7 @@ public static void print(PrintableNode root) {
8686
if (line.get(j - 1) != null) {
8787
c = (line.get(j) != null) ? '┴' : '┘';
8888
} else {
89-
if (j < line.size() && line.get(j) != null) c = '└';
89+
if (line.get(j) != null) c = '└';
9090
}
9191
}
9292
System.out.print(c);
@@ -111,9 +111,8 @@ public static void print(PrintableNode root) {
111111
}
112112

113113
// print line of numbers
114-
for (int j = 0; j < line.size(); j++) {
114+
for (String f : line) {
115115

116-
String f = line.get(j);
117116
if (f == null) f = "";
118117
int gap1 = (int) Math.ceil(perpiece / 2f - f.length() / 2f);
119118
int gap2 = (int) Math.floor(perpiece / 2f - f.length() / 2f);
@@ -132,4 +131,4 @@ public static void print(PrintableNode root) {
132131
perpiece /= 2;
133132
}
134133
}
135-
}
134+
}

0 commit comments

Comments
 (0)