![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Simple binary tree. More...
Public Member Functions | |
BinaryTree (T data) | |
create new root node without children More... | |
BinaryTree (T data, BinaryTree< T > left, BinaryTree< T > right) | |
create new root node with children More... | |
BinaryTree< T > | setLeft (BinaryTree< T > tree) |
set left subtree More... | |
BinaryTree< T > | setRight (BinaryTree< T > tree) |
set right subtree More... | |
void | setData (T data) |
set node data More... | |
T | getData () |
get node data More... | |
BinaryTree< T > | getParent () |
get node's parent or null for root More... | |
BinaryTree< T > | getLeft () |
get left child or null More... | |
BinaryTree< T > | getRight () |
get right child or null ) More... | |
String | toDot () |
Get dot representation. More... | |
GraphvizDecorator | getDecorator () |
get decoration or null More... | |
boolean | isRoot () |
Iscode this} root? More... | |
boolean | isLeaf () |
Is this a leaf? More... | |
BinaryTree< T > | getRoot () |
traverse upwards to find root node More... | |
BinaryTreeTraversal< T >.Preorder | preorder () |
Get preorder iterator over nodes in tree . More... | |
BinaryTreeTraversal< T >.Inorder | inorder () |
Get inorder iterator over nodes in tree . More... | |
BinaryTreeTraversal< T >.Postorder | postorder () |
Get postorder iterator over nodes in tree . More... | |
BinaryTreeTraversal< T >.Levelorder | levelorder () |
Get level-order iterator over nodes in tree . More... | |
String | toString () |
Get string presentation of node data. More... | |
GraphvizDecorator | getDecorator () |
get decoration or null More... | |
String | toDot () |
Get dot representation. More... | |
String | toText () |
get multiline text visualization More... | |
String | toTikZ () |
get TikZ code for LaTeX export More... | |
String | dotLabel () |
String | textLabel () |
Get string representation of data in toText . More... | |
String | tikzNodeStyle () |
String | toTikZ (int level) |
static void | main (String[] args) |
Simple binary tree.
The BinaryTree
class represents a node and simultaneously its subtree. We do not explclitly distinguish between nodes and a (rooted) tree.
Used for demos (e.g., aud.example.BinaryTreeTraversal
) and as base class for various binary trees.
For every node, we store an uplink to its parent, see getParent
.
Definition at line 25 of file BinaryTree.java.
aud.BinaryTree< T >.BinaryTree | ( | T | data | ) |
create new root node without children
Definition at line 34 of file BinaryTree.java.
aud.BinaryTree< T >.BinaryTree | ( | T | data, |
BinaryTree< T > | left, | ||
BinaryTree< T > | right | ||
) |
create new root node with children
Definition at line 41 of file BinaryTree.java.
|
protected |
Definition at line 193 of file BinaryTree.java.
References aud.BinaryTree< T >.getData().
T aud.BinaryTree< T >.getData | ( | ) |
get node data
Definition at line 81 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.dotLabel(), aud.example.expr.Divide.getValue(), aud.example.expr.ExpressionTree.getValue(), aud.example.expr.Minus.getValue(), aud.example.expr.Plus.getValue(), aud.example.expr.Power.getValue(), aud.example.expr.Times.getValue(), aud.example.expr.UnaryMinus.getValue(), aud.example.expr.ExpressionTreeTraversal.output(), aud.BinaryTree< T >.textLabel(), aud.BinaryTree< T >.toString(), aud.BinaryTreeTraversal< T >.Traversal.toString(), aud.example.expr.ExpressionTree.toString(), and aud.BinaryTree< T >.toTikZ().
GraphvizDecorator aud.BinaryTree< T >.getDecorator | ( | ) |
get decoration or null
Implements aud.util.GraphvizDecorable.
Reimplemented in aud.example.expr.ExpressionTree.
Definition at line 158 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.toDot().
BinaryTree< T > aud.BinaryTree< T >.getLeft | ( | ) |
get left child or null
Definition at line 86 of file BinaryTree.java.
Referenced by aud.example.expr.Divide.getValue(), aud.example.expr.Minus.getValue(), aud.example.expr.Plus.getValue(), aud.example.expr.Power.getValue(), aud.example.expr.Times.getValue(), aud.example.expr.UnaryMinus.getValue(), aud.example.expr.ExpressionTreeTraversal.inorder(), aud.BinaryTree< T >.isLeaf(), aud.example.IterativePreorderTraversal.iterative_traversal(), aud.example.IterativePreorderTraversal.level_order_traversal(), aud.example.expr.ExpressionTreeTraversal.levelorder(), aud.example.expr.ExpressionTreeTraversal.postorder(), aud.example.expr.ExpressionTreeTraversal.preorder(), aud.example.IterativePreorderTraversal.recursive_traversal(), aud.test.BinaryTreeTest.testBinaryTree(), aud.example.expr.ExpressionTree.toString(), and aud.BinaryTree< T >.toTikZ().
BinaryTree< T > aud.BinaryTree< T >.getParent | ( | ) |
get node's parent or null
for root
Definition at line 84 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.getRoot(), aud.BinaryTree< T >.isRoot(), and aud.test.BinaryTreeTest.testBinaryTree().
BinaryTree< T > aud.BinaryTree< T >.getRight | ( | ) |
get right child or null
)
Definition at line 88 of file BinaryTree.java.
Referenced by aud.example.expr.Divide.getValue(), aud.example.expr.Minus.getValue(), aud.example.expr.Plus.getValue(), aud.example.expr.Power.getValue(), aud.example.expr.Times.getValue(), aud.example.expr.UnaryMinus.getValue(), aud.example.expr.ExpressionTreeTraversal.inorder(), aud.BinaryTree< T >.isLeaf(), aud.example.IterativePreorderTraversal.iterative_traversal(), aud.example.IterativePreorderTraversal.level_order_traversal(), aud.example.expr.ExpressionTreeTraversal.levelorder(), aud.example.expr.ExpressionTreeTraversal.postorder(), aud.example.expr.ExpressionTreeTraversal.preorder(), aud.example.IterativePreorderTraversal.recursive_traversal(), aud.test.BinaryTreeTest.testBinaryTree(), aud.example.expr.ExpressionTree.toString(), and aud.BinaryTree< T >.toTikZ().
BinaryTree< T > aud.BinaryTree< T >.getRoot | ( | ) |
traverse upwards to find root node
Definition at line 103 of file BinaryTree.java.
References aud.BinaryTree< T >.getParent(), and aud.BinaryTree< T >.isRoot().
Referenced by aud.test.BinaryTreeTest.testBinaryTree().
BinaryTreeTraversal< T >.Inorder aud.BinaryTree< T >.inorder | ( | ) |
Get inorder iterator over nodes in tree .
Iterable
Definition at line 126 of file BinaryTree.java.
References aud.BinaryTreeTraversal< T >.inorder().
Referenced by aud.BinaryTree< T >.main(), and aud.test.BinaryTreeTest.testBinaryTree().
boolean aud.BinaryTree< T >.isLeaf | ( | ) |
Is this
a leaf?
Definition at line 96 of file BinaryTree.java.
References aud.BinaryTree< T >.getLeft(), and aud.BinaryTree< T >.getRight().
Referenced by aud.example.expr.AtomicExpression.isTerminal(), aud.test.BinaryTreeTest.testBinaryTree(), and aud.example.expr.ExpressionTree.toString().
boolean aud.BinaryTree< T >.isRoot | ( | ) |
Iscode this} root?
Definition at line 92 of file BinaryTree.java.
References aud.BinaryTree< T >.getParent().
Referenced by aud.BinaryTree< T >.getRoot(), aud.test.BinaryTreeTest.testBinaryTree(), and aud.example.expr.ExpressionTree.toString().
BinaryTreeTraversal< T >.Levelorder aud.BinaryTree< T >.levelorder | ( | ) |
Get level-order iterator over nodes in tree .
Iterable
Definition at line 142 of file BinaryTree.java.
References aud.BinaryTreeTraversal< T >.levelorder().
Referenced by aud.BinaryTree< T >.main(), and aud.test.BinaryTreeTest.testBinaryTree().
|
static |
Reimplemented in aud.example.expr.ExpressionTree.
Definition at line 281 of file BinaryTree.java.
References aud.BinaryTree< T >.inorder(), aud.BinaryTree< T >.levelorder(), aud.BinaryTree< T >.postorder(), aud.BinaryTree< T >.preorder(), aud.BinaryTree< T >.setLeft(), aud.BinaryTree< T >.setRight(), aud.BinaryTreeTraversal< T >.Traversal.toString(), aud.BinaryTree< T >.toText(), and aud.BinaryTree< T >.toTikZ().
BinaryTreeTraversal< T >.Postorder aud.BinaryTree< T >.postorder | ( | ) |
Get postorder iterator over nodes in tree .
Iterable
Definition at line 134 of file BinaryTree.java.
References aud.BinaryTreeTraversal< T >.postorder().
Referenced by aud.BinaryTree< T >.main(), aud.example.expr.ExpressionParser.main(), aud.example.expr.ExpressionParser2.main(), aud.example.expr.ExpressionTree.main(), and aud.test.BinaryTreeTest.testBinaryTree().
BinaryTreeTraversal< T >.Preorder aud.BinaryTree< T >.preorder | ( | ) |
Get preorder iterator over nodes in tree .
Examples:
Iterator<BinaryTree<T> > ii=tree.preorder().iterator();
for (BinaryTree<T> node : tree.preorder()) { ... }
Iterable
Definition at line 118 of file BinaryTree.java.
References aud.BinaryTreeTraversal< T >.preorder().
Referenced by aud.BinaryTree< T >.main(), and aud.test.BinaryTreeTest.testBinaryTree().
void aud.BinaryTree< T >.setData | ( | T | data | ) |
BinaryTree< T > aud.BinaryTree< T >.setLeft | ( | BinaryTree< T > | tree | ) |
set left subtree
null
Definition at line 55 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.main(), and aud.test.BinaryTreeTest.testBinaryTree().
BinaryTree< T > aud.BinaryTree< T >.setRight | ( | BinaryTree< T > | tree | ) |
set right subtree
null
Definition at line 68 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.main(), and aud.test.BinaryTreeTest.testBinaryTree().
|
protected |
Get string representation of data in toText
.
getData().toString()
(default implementation) Definition at line 263 of file BinaryTree.java.
References aud.BinaryTree< T >.getData().
|
protected |
Definition at line 269 of file BinaryTree.java.
Referenced by aud.BinaryTree< T >.toTikZ().
String aud.BinaryTree< T >.toDot | ( | ) |
Get dot representation.
Implements aud.util.Graphvizable.
Definition at line 162 of file BinaryTree.java.
References aud.BinaryTree< T >.getDecorator(), aud.util.GraphvizDecorator.getGlobalStyle(), and aud.util.GraphvizDecorator.getGraphDecoration().
String aud.BinaryTree< T >.toString | ( | ) |
Get string presentation of node data.
This method only encodes the node's content as string, it does not encode the entire tree! (This makes it easier to, e.g., print out a Stack
of nodes.)
getData
.toString
Reimplemented in aud.example.expr.ExpressionTree.
Definition at line 154 of file BinaryTree.java.
References aud.BinaryTree< T >.getData().
String aud.BinaryTree< T >.toText | ( | ) |
get multiline text visualization
Definition at line 235 of file BinaryTree.java.
References aud.BinaryTree< T >.toText().
Referenced by aud.BinaryTree< T >.main(), and aud.BinaryTree< T >.toText().
String aud.BinaryTree< T >.toTikZ | ( | ) |
get TikZ code for LaTeX export
Definition at line 266 of file BinaryTree.java.
References aud.BinaryTree< T >.toTikZ().
Referenced by aud.BinaryTree< T >.main(), aud.example.expr.ExpressionParser.main(), aud.example.expr.ExpressionParser2.main(), and aud.BinaryTree< T >.toTikZ().
|
protected |
Definition at line 270 of file BinaryTree.java.
References aud.BinaryTree< T >.getData(), aud.BinaryTree< T >.getLeft(), aud.BinaryTree< T >.getRight(), aud.util.Sys.indent(), and aud.BinaryTree< T >.tikzNodeStyle().