public class Tree
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
POSTORDER
The postorder constant.
|
static java.lang.String |
PREORDER
The preorder constant.
|
protected TreeNode |
root
The root node.
|
Constructor and Description |
---|
Tree()
Create a new tree.
|
Tree(TreeNode root)
Create a new tree.
|
Modifier and Type | Method and Description |
---|---|
TreeNode |
getRootNode()
Return the root node of the tree.
|
boolean |
isEmpty()
Test if empty.
|
void |
setRootElement(TreeNode root)
Set the root node for the tree.
|
java.util.List |
toList(java.lang.String order)
Returns the tree as a List of node objects.
|
java.lang.String |
toString()
Returns a String representation of the tree.
|
protected void |
walkPostorder(TreeNode node,
java.util.List list)
Walks the tree in post-order style.
|
protected void |
walkPreorder(TreeNode node,
java.util.List list)
Walks the tree in pre-order style.
|
public static final java.lang.String PREORDER
public static final java.lang.String POSTORDER
protected TreeNode root
public Tree()
public Tree(TreeNode root)
public TreeNode getRootNode()
public void setRootElement(TreeNode root)
root
- The root node to set.public java.util.List toList(java.lang.String order)
public boolean isEmpty()
public java.lang.String toString()
toString
in class java.lang.Object
protected void walkPreorder(TreeNode node, java.util.List list)
node
- The starting element.list
- The output of the walk.protected void walkPostorder(TreeNode node, java.util.List list)
node
- The starting element.list
- The output of the walk.