|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jpaul.Graphs.BinTreeUtil
public final class BinTreeUtil
BinTreeUtil
is a wrapper for binary tree utilities.
It is a non-instantiatable class with useful static members,
similar to java.util.Collections
.
Method Summary | ||
---|---|---|
static
|
inOrder(T2 root,
BinTreeNavigator<T2> binTreeNav)
Returns an iterator that traverses all vertices of a binary tree in inorder. |
|
static
|
inOrder(T root,
BinTreeNavigator<T> binTreeNav,
Action<T> action)
Executes an action on all nodes from a tree, in inorder. |
|
static
|
postOrder(T2 root,
BinTreeNavigator<T2> binTreeNav)
Returns an iterator that traverses all vertices of a binary tree in postorder. |
|
static
|
postOrder(T root,
BinTreeNavigator<T> binTreeNav,
Action<T> action)
Executes an action on all nodes from a tree, in postorder. |
|
static
|
preOrder(T2 root,
BinTreeNavigator<T2> binTreeNav)
Returns an iterator that traverses all vertices of a binary tree in preorder. |
|
static
|
preOrder(T root,
BinTreeNavigator<T> binTreeNav,
Action<T> action)
Executes an action on all nodes from a tree, in preorder. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> void inOrder(T root, BinTreeNavigator<T> binTreeNav, Action<T> action)
root
- Binary tree root.binTreeNav
- Binary tree navigator.action
- Action to execute on each tree node.public static <T> void preOrder(T root, BinTreeNavigator<T> binTreeNav, Action<T> action)
root
- Binary tree root.binTreeNav
- Binary tree navigator.action
- Action to execute on each tree node.public static <T> void postOrder(T root, BinTreeNavigator<T> binTreeNav, Action<T> action)
root
- Binary tree root.binTreeNav
- Binary tree navigator.action
- Action to execute on each tree node.public static <T,T2 extends T> java.util.Iterator<T> inOrder(T2 root, BinTreeNavigator<T2> binTreeNav)
Note1: the complication with two type parameters simulates the common-sense fact that the iterator subtyping is co-variant with the element subtyping.
Note2: supports trees with sharing; shared nodes will be returned multiple times.
Note3: of we had a parent pointer, it would have been possible to do the traversal with O(1) additional space; however, to simplify the interface, no such information is provided by the tree navigator, and we have to maintain an explicit stack of parent nodes.
root
- The root node of the binary tree.binTreeNav
- The binary tree navigator.public static <T,T2 extends T> java.util.Iterator<T> preOrder(T2 root, BinTreeNavigator<T2> binTreeNav)
All notes for inOrder
apply to this method too.
root
- The root node of the binary tree.binTreeNav
- The binary tree navigator.public static <T,T2 extends T> java.util.Iterator<T> postOrder(T2 root, BinTreeNavigator<T2> binTreeNav)
All notes for inOrder
apply to this method too.
root
- The root node of the binary tree.binTreeNav
- The binary tree navigator.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |