Class BinaryTree
java.lang.Object
|
+--BinaryTree
- public class BinaryTree
- extends java.lang.Object
Class BinaryTree defines a basic binary tree data structure with
Object-valued nodes. The class provides constructor, find, and toString
methods. See also the BinarySearchTree
class. The difference between this plain BinaryTree class versus
BinarySearchTree is that this class does not maintain the nodes in any kind
of sorted order, as is done in BinarySearchTree.
This BinaryTree class uses the public class
BinaryTreeNode as the definition of a tree node.
Method Summary |
BinaryTreeNode |
find(java.lang.Object value)
Return a pointer to the first node containing the given value, using a
preorder traversal. |
protected BinaryTreeNode |
findPreorder(java.lang.Object value,
BinaryTreeNode t)
Recursive work doer for find. |
java.lang.String |
toString()
Convert this to a preorder string of the form:
root
left subtree ... |
protected java.lang.String |
toString(BinaryTreeNode t,
int indent)
Recursive work doer for toString(), converting the given node value to a
string, preceded by indent spacing, followed by the recursive toString
of the left and right subtrees. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
BinaryTree
public BinaryTree(BinaryTreeNode root)
- Construct this with the given node as the root.
find
public BinaryTreeNode find(java.lang.Object value)
- Return a pointer to the first node containing the given value, using a
preorder traversal.
findPreorder
protected BinaryTreeNode findPreorder(java.lang.Object value,
BinaryTreeNode t)
- Recursive work doer for find.
toString
public java.lang.String toString()
- Convert this to a preorder string of the form:
root
left subtree ...
right subtree ...
I.e., the root is on the first line, subtrees are on subsequent lines,
each indented two spaces for each level of the tree.
- Overrides:
toString
in class java.lang.Object
toString
protected java.lang.String toString(BinaryTreeNode t,
int indent)
- Recursive work doer for toString(), converting the given node value to a
string, preceded by indent spacing, followed by the recursive toString
of the left and right subtrees.