44 left_=left; right_=right;
45 if (left!=
null) left_.parent_ =
this;
46 if (right!=
null) right_.parent_=
this;
79 public void setData(T data) { data_=data; }
163 String dot=
"graph BinaryTree {\n";
166 if (decorator!=
null) {
168 if (d!=
null) dot+=
" "+d+
";\n";
170 if (d!=
null) dot+=
" graph ["+d+
"];\n";
186 private String dotRef() {
187 return getData().toString()+
"-"+hashCode();
196 private String treeToDot() {
200 String dot =
" \""+dotRef()+
"\" [label=\""+
dotLabel()+
"\",";
207 dot+=dotLeaf(
"left");
212 dot+=dotLeaf(
"right");
217 dot+=
" \""+
getParent().dotRef()+
"\" -- \""+
227 private String dotLeaf(String side) {
228 String dummy=
"\""+dotRef()+
"-"+side+
"\"";
229 String dot=
" "+dummy+
" [shape=point];\n";
230 dot+=
" \""+dotRef()+
"\" -- "+dummy+
" [];\n";
240 private String
toText(
int level) {
248 text+=
getLeft().toText(level+1);
267 return "\\"+
toTikZ(0)+
";\n";
274 tex+=spaces+
" child[left] {\n"+
getLeft().toTikZ(level+1)+spaces+
" }\n";
276 tex+=spaces+
" child[right] {\n"+
getRight().toTikZ(level+1)+spaces+
" }\n";
281 public static void main(String[] args) {
291 System.out.println(a);
292 System.out.println(a.
toText());
293 System.out.println(a.
toTikZ());
helper: generates InorderIterator
helper: generates LevelorderIterator
helper: generates PostorderIterator
helper: generates PreorderIterator
Provide traversals of binary trees.
Postorder postorder(BinaryTree< T > tree)
return instance of generator
Preorder preorder(BinaryTree< T > tree)
return instance of generator
Inorder inorder(BinaryTree< T > tree)
return instance of generator
Levelorder levelorder(BinaryTree< T > tree)
return instance of generator
static void main(String[] args)
String toText()
get multiline text visualization
String toDot()
Get dot representation.
void setData(T data)
set node data
BinaryTree< T > setRight(BinaryTree< T > tree)
set right subtree
BinaryTreeTraversal< T >.Inorder inorder()
Get inorder iterator over nodes in tree .
BinaryTree< T > setLeft(BinaryTree< T > tree)
set left subtree
BinaryTree(T data, BinaryTree< T > left, BinaryTree< T > right)
create new root node with children
BinaryTree< T > getLeft()
get left child or null
BinaryTree< T > getRoot()
traverse upwards to find root node
BinaryTreeTraversal< T >.Preorder preorder()
Get preorder iterator over nodes in tree .
BinaryTreeTraversal< T >.Postorder postorder()
Get postorder iterator over nodes in tree .
String textLabel()
Get string representation of data in toText.
String toTikZ()
get TikZ code for LaTeX export
BinaryTree< T > getRight()
get right child or null)
boolean isLeaf()
Is this a leaf?
BinaryTree(T data)
create new root node without children
String toString()
Get string presentation of node data.
BinaryTree< T > getParent()
get node's parent or null for root
GraphvizDecorator getDecorator()
get decoration or null
BinaryTreeTraversal< T >.Levelorder levelorder()
Get level-order iterator over nodes in tree .
boolean isRoot()
Iscode this} root?
Decorator for items of Graphvizable objects.
String getFullNodeDecoration(GraphvizDecorable object)
concatenates getAllNodesDecoration and getNodeDecoration
String getFullEdgeDecoration(GraphvizDecorable object)
concatenates getAllEdgesDecoration and getEdgeDecoration
String getGlobalStyle()
get global style (returns same for all nodes/edges)
String getGraphDecoration(GraphvizDecorable object)
get graph decoration (returns same for all nodes/edges)
System related utilities.
static String indent(int level)
get indentation string filled with spaces
Interface for decorating items of Graphvizable objects.
Interface for GraphViz rendering.
utilities (not related to AuD lecture)
AuD lecture: Data structures, algorithms, examples.