Package aud
Class BinaryTree<T>
java.lang.Object
aud.BinaryTree<T>
- All Implemented Interfaces:
Graphvizable
,GraphvizDecorable
- Direct Known Subclasses:
BinarySearchTree.Node
,ExpressionTree
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., BinaryTreeTraversal
) and
as base class for various binary trees.
For every node, we store an uplink to its parent, see
getParent()
.
-
Constructor Summary
ConstructorsConstructorDescriptionBinaryTree
(T data) create new root node without childrenBinaryTree
(T data, BinaryTree<T> left, BinaryTree<T> right) create new root node with children -
Method Summary
Modifier and TypeMethodDescriptionprotected String
dotLabel()
getData()
get node dataget decoration ornull
getLeft()
get left child ornull
get node's parent ornull
for rootgetRight()
get right child ornull
)getRoot()
traverse upwards to find root nodeinorder()
Get inorder iterator over nodes in tree .boolean
isLeaf()
Isthis
a leaf?boolean
isRoot()
Is @{code this} root?Get level-order iterator over nodes in tree .static void
Get postorder iterator over nodes in tree .preorder()
Get preorder iterator over nodes in tree .void
set node datasetLeft
(BinaryTree<T> tree) set left subtreesetRight
(BinaryTree<T> tree) set right subtreeprotected String
Get string representation of data intoText()
protected String
toDot()
Get dot representation.toString()
Get string presentation of node data.toText()
get multiline text visualizationtoTikZ()
get TikZ code for LaTeX exportprotected String
toTikZ
(int level)
-
Constructor Details
-
BinaryTree
create new root node without children -
BinaryTree
create new root node with children
-
-
Method Details
-
setLeft
set left subtree- Returns:
- previous subtree or
null
-
setRight
set right subtree- Returns:
- previous subtree or
null
-
setData
set node data -
getData
get node data -
getParent
get node's parent ornull
for root -
getLeft
get left child ornull
-
getRight
get right child ornull
) -
isRoot
public boolean isRoot()Is @{code this} root? -
isLeaf
public boolean isLeaf()Isthis
a leaf? -
getRoot
traverse upwards to find root node -
preorder
Get preorder iterator over nodes in tree .Examples:
Iterator<BinaryTree<T> > ii=tree.preorder().iterator();
for (BinaryTree<T> node : tree.preorder()) { ... }
- Returns:
- instance of
Iterable
- See Also:
-
inorder
Get inorder iterator over nodes in tree .- Returns:
- instance of
Iterable
- See Also:
-
postorder
Get postorder iterator over nodes in tree .- Returns:
- instance of
Iterable
- See Also:
-
levelorder
Get level-order iterator over nodes in tree .- Returns:
- instance of
Iterable
- See Also:
-
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.) -
getDecorator
Description copied from interface:GraphvizDecorable
get decoration ornull
- Specified by:
getDecorator
in interfaceGraphvizDecorable
-
toDot
Description copied from interface:Graphvizable
Get dot representation.- Specified by:
toDot
in interfaceGraphvizable
-
dotLabel
-
toText
get multiline text visualization -
textLabel
Get string representation of data intoText()
- Returns:
getData().toString()
(default implementation)
-
toTikZ
get TikZ code for LaTeX export -
tikzNodeStyle
-
toTikZ
-
main
-