java.lang.ObjectBinaryTree
public class BinaryTree
Implements loop-free binary trees, allowing shared subtrees.
| Field Summary | |
|---|---|
java.lang.Object |
value
The value (data) in this node of the binary tree; may be of any object type. |
| Constructor Summary | |
|---|---|
BinaryTree(java.lang.Object value)
Constructor for a BinaryTree leaf node (that is, with no children). |
|
BinaryTree(java.lang.Object value,
BinaryTree leftChild,
BinaryTree rightChild)
Constructor for BinaryTree. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object o)
Tests whether this BinaryTree is equal to the given object. |
BinaryTree |
getLeftChild()
Getter method for left child of this BinaryTree node. |
BinaryTree |
getRightChild()
Getter method for right child of this BinaryTree node. |
java.lang.Object |
getValue()
Getter method for the value in this BinaryTree node. |
int |
hashCode()
Computes a hash code for the complete binary tree rooted at this BinaryTree node. |
boolean |
isLeaf()
Tests whether this node is a leaf node. |
void |
print()
Prints the binary tree rooted at this BinaryTree node. |
void |
setLeftChild(BinaryTree subtree)
Sets the left child of this BinaryTree node to be the given subtree. |
void |
setRightChild(BinaryTree subtree)
Sets the right child of this BinaryTree node to be the given subtree. |
void |
setValue(java.lang.Object value)
Sets the value in this BinaryTree node. |
java.lang.String |
toString()
Returns a String representation of this BinaryTree. |
| Methods inherited from class java.lang.Object |
|---|
getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public java.lang.Object value
| Constructor Detail |
|---|
public BinaryTree(java.lang.Object value,
BinaryTree leftChild,
BinaryTree rightChild)
value - The value to be placed in the root.leftChild - The left child of the root (may be null).rightChild - The right child of the root (may be null).public BinaryTree(java.lang.Object value)
value - The value to be placed in the root.| Method Detail |
|---|
public java.lang.Object getValue()
public BinaryTree getLeftChild()
null if no left child).public BinaryTree getRightChild()
null if no right child).
public void setLeftChild(BinaryTree subtree)
throws java.lang.IllegalArgumentException
IllegalArgumentException
if the operation would cause a loop in the binary tree.
subtree - The node to be added as the new left child.
java.lang.IllegalArgumentException - If the operation would cause
a loop in the binary tree.
public void setRightChild(BinaryTree subtree)
throws java.lang.IllegalArgumentException
IllegalArgumentException
if the operation would cause a loop in the binary tree.
subtree - The node to be added as the new right child.
java.lang.IllegalArgumentException - If the operation would cause
a loop in the binary tree.public void setValue(java.lang.Object value)
value - The new value.public boolean isLeaf()
true if this BinaryTree node has no children.public boolean equals(java.lang.Object o)
equals in class java.lang.Objecttrue if the binary trees are equal.Object.equals(java.lang.Object)public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()public void print()