

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object BinaryTree<V>
V
 The type of values contained in this BinaryTree.public class BinaryTree<V>
A BinaryTree consists of "nodes"each "node" is itself a BinaryTree. Each node has a parent (unless it is the root), may have a left child, and may have a right child. This class implements loopfree binary trees, allowing shared subtrees.
Field Summary  

V 
value
The value (data) in this node of the binary tree; may be of any object type. 
Constructor Summary  

BinaryTree(V value)
Constructor for a BinaryTree leaf node (that is, with no children). 

BinaryTree(V value,
BinaryTree<V> leftChild,
BinaryTree<V> rightChild)
Constructor for BinaryTree. 
Method Summary  

protected static boolean 
contains(BinaryTree tree,
BinaryTree targetNode)
Tests whether the tree argument contains within
itself the targetNode argument. 
boolean 
containsEqualValue(V value)
Returns true if and only if some node in this binary tree contains a value that is equal to the parameter. 
boolean 
containsSameValue(V value)
Returns true if and only if some node in this binary tree contains the same object (not just an equal object) as the one given for the value parameter. 
BinaryTree<V> 
copy()
Returns a new BinaryTree equal to (but not the same as) this binary tree. 
int 
depth()
Returns the depth of this binary tree. 
boolean 
equals(java.lang.Object o)
Tests whether this BinaryTree is equal to the given object. 
java.util.List<V> 
fringe()
Returns a List of the values (of type V) in the leaves of this binary tree, in lefttoright order. 
BinaryTree<V> 
getLeftChild()
Getter method for left child of this BinaryTree node. 
BinaryTree<V> 
getRightChild()
Getter method for right child of this BinaryTree node. 
V 
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. 
java.util.Set<BinaryTree<V>> 
leaves()
Returns a Set of all the leaves of this binary tree. 
BinaryTree<V> 
leftmostDescendant()
Returns the leftmost descendant of this binary tree. 
int 
numberOfNodes()
Returns the total number of nodes in this binary tree (include the root in the count). 
void 
print()
Prints the binary tree rooted at this BinaryTree node. 
BinaryTree<V> 
reverse()
Returns a new binary tree which is the mirror image of the binary tree whose root is at this binary tree. 
void 
reverseInPlace()
Rearranges the binary tree rooted at this binary tree to be the mirror image of its original structure. 
BinaryTree<V> 
rightmostDescendant()
Returns the rightmost descendant of this binary tree. 
void 
setLeftChild(BinaryTree<V> subtree)
Sets the left child of this BinaryTree node to be the given subtree. 
void 
setRightChild(BinaryTree<V> subtree)
Sets the right child of this BinaryTree node to be the given subtree. 
void 
setValue(V value)
Sets the value in this BinaryTree node. 
java.lang.String 
toString()
Returns a String representation of this BinaryTree. 
java.util.Set<V> 
valuesOf()
Returns a Set of the values (of type V) in this binary tree. 
Methods inherited from class java.lang.Object 

clone, finalize, getClass, notify, notifyAll, wait, wait, wait 
Field Detail 

public V value
Constructor Detail 

public BinaryTree(V value, BinaryTree<V> leftChild, BinaryTree<V> 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(V value)
value
 The value to be placed in the root.Method Detail 

public V getValue()
public BinaryTree<V> getLeftChild()
null
if no left child).public BinaryTree<V> getRightChild()
null
if no right child).public void setLeftChild(BinaryTree<V> 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<V> 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(V 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.Object
true
if the binary trees are equal.Object.equals(java.lang.Object)
protected static boolean contains(BinaryTree tree, BinaryTree targetNode)
tree
argument contains within
itself the targetNode
argument.
tree
 The root of the binary tree to search.targetNode
 The node to be searched for.
true
if the targetNode
argument can
be found within the binary tree rooted at tree
.public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public void print()
public BinaryTree<V> leftmostDescendant()
public BinaryTree<V> rightmostDescendant()
public int numberOfNodes()
public int depth()
public boolean containsEqualValue(V value)
value
 The value to be searched for.
true
if this BinaryTree contains an equal value.public boolean containsSameValue(V value)
value
 The value to be searched for.
true
if this BinaryTree contains the identical value.public java.util.Set<BinaryTree<V>> leaves()
public java.util.Set<V> valuesOf()
public java.util.List<V> fringe()
public BinaryTree<V> copy()
public BinaryTree<V> reverse()
public void reverseInPlace()


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 