A simple program to print all the nodes in the tree with a beautiful output. Connected by lines with clear paths, it's nice to look and easy to debug a tree.
Download TreeVisualizer.java
and put it in the same directory so you won't need to import anything
- Put
TreeVisualizer.java
in the same directory with theNode
file (to implement) andTree
file (to print) - Implements
Visualized
fromTreeVisualizer
to yourNode
class - Override
getLeft
,getRight
, andgetValue
method with your values
class Node implements TreeVisualizer.Visualized {
Node left, right;
String name;
...
@Override
public TreeVisualizer.Visualized getLeft() {
return this.left;
}
@Override
public TreeVisualizer.Visualized getRight() {
return this.right;
}
@Override
public String getValue() {
return this.name;
}
}
- If your
Value
is other than aString
, you need to modify it to return your data type - Use the provided
print
method and put the tree'sroot
as the argument
public class MyFile {
public static void main(String[] args) {
Tree tree = new Tree();
TreeVisualizer.print(tree.root);
}
}
or
public class MyFile {
public static void main(String[] args) {
Tree tree = new Tree();
tree.print()
}
}
class Tree {
Node root;
...
public void print() {
TreeVisualizer.print(this.root);
}
}