UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.graphs
Class BinaryTree

java.lang.Object
  |
  +--edu.berkeley.guir.lib.graphs.BinaryTree
Direct Known Subclasses:
BinarySearchTree, PathTree

public class BinaryTree
extends Object

An abstract tree that has at most two children per node.

This software is distributed under the Berkeley Software License.

 Revisions:  - GUIRLib-v1.0-1.0.0, Nov 25 1997, JH
               Created class
             - GUIRLib-v1.0-1.1.0, Feb 24 2000, JH
               Updated for JDK1.3RC1 to use the Collections
             - GUIRLib-v1.2-1.0.0, Jun 22 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.3-1.0.0, Aug 11 2000, JH
               Touched for GUIRLib release
             - GUIRLib-v1.4-1.0.0, Aug 31 2000, JH
               Touched for GUIRLib release
 

Since:
JDK 1.2
Version:
GUIRLib-v1.4-1.0.0, Aug 31 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu)

Field Summary
protected  Object data
           
protected  BinaryTree left
           
protected  BinaryTree right
           
 
Constructor Summary
BinaryTree()
          Default constructor, creates an empty binary tree.
BinaryTree(Object data)
          Creates a binary tree with the specified object at the root.
BinaryTree(Object data, BinaryTree left, BinaryTree right)
          Creates a binary tree with the specified object at the root.
 
Method Summary
protected  Object _data()
          Retrieve the data at the root of this tree.
protected  BinaryTree _left()
          Retrieve the left child of this tree.
protected  BinaryTree _right()
          Retrieve the right child of this tree.
protected  void _setData(Object obj)
          Set the value that this BinaryTree holds.
protected  void _setLeft(BinaryTree left)
          Set the left subtree of this BinaryTree.
protected  void _setRight(BinaryTree right)
          Set the right subtree of this BinaryTree.
protected  void add(Object obj)
          Adds this object to the tree.
 boolean equals(Object obj)
           
 boolean exists(Object obj)
          See if the specified Object is in the tree or not.
 int getNumberOfElements()
          Get the number of elements in this tree.
 Enumeration inOrderTraversal()
          Get the elements of the tree through an in-order traversal.
 Enumeration postOrderTraversal()
          Get the elements of the tree through an post-order traversal.
 Enumeration preOrderTraversal()
          Get the elements of the tree through an pre-order traversal.
protected  void remove(Object obj)
          Remove an object from this tree.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected Object data

left

protected BinaryTree left

right

protected BinaryTree right
Constructor Detail

BinaryTree

public BinaryTree()
Default constructor, creates an empty binary tree.

BinaryTree

public BinaryTree(Object data)
Creates a binary tree with the specified object at the root.
Parameters:
data - is the value for the root of this BinaryTree.

BinaryTree

public BinaryTree(Object data,
                  BinaryTree left,
                  BinaryTree right)
Creates a binary tree with the specified object at the root.
Parameters:
data - is the value for the root of this BinaryTree.
left - is the left subtree of this BinaryTree.
right - is the right subtree of this BinaryTree.
Method Detail

exists

public boolean exists(Object obj)
See if the specified Object is in the tree or not. Override this method for functionality.
Parameters:
obj - is the Object to check for in the tree.
Returns:
true if the Object is in the tree, false otherwise. Currently returns false always.

add

protected void add(Object obj)
Adds this object to the tree. Override this method for functionality.
Parameters:
obj - is the Object to add to the tree.

remove

protected void remove(Object obj)
Remove an object from this tree. Override this method for functionality.
Parameters:
obj - is the Object to remove from the tree.

getNumberOfElements

public int getNumberOfElements()
Get the number of elements in this tree.
Returns:
the number of elements currently in this tree.

_data

protected Object _data()
Retrieve the data at the root of this tree. If this object is modified, there is no guarantee that the BinaryTree will be ordered consistently!

This is an internal method. You can create another method named data() to return the right kind of object if necessary.

Returns:
an Object that is the data at the root of this tree.

_left

protected BinaryTree _left()
Retrieve the left child of this tree.

This is an internal method. You can create another method named left() to return the correct kind of BinaryTree if necessary.

Returns:
the left child of this tree.

_right

protected BinaryTree _right()
Retrieve the right child of this tree.

This is an internal method. You can create another method named right() to return the correct kind of BinaryTree if necessary.

Returns:
the right child of this tree.

inOrderTraversal

public Enumeration inOrderTraversal()
Get the elements of the tree through an in-order traversal. This only captures the current state of the tree, and will not reflect any changes to the tree made after this method is called.
Returns:
an Enumeration of elements of this tree in-order.

preOrderTraversal

public Enumeration preOrderTraversal()
Get the elements of the tree through an pre-order traversal. This only captures the current state of the tree, and will not reflect any changes to the tree made after this method is called.
Returns:
an Enumeration of elements of this tree pre-order.

postOrderTraversal

public Enumeration postOrderTraversal()
Get the elements of the tree through an post-order traversal. This only captures the current state of the tree, and will not reflect any changes to the tree made after this method is called.
Returns:
an Enumeration of elements of this tree post-order.

_setLeft

protected void _setLeft(BinaryTree left)
Set the left subtree of this BinaryTree.
Parameters:
left - is a BinaryTree that will be the left subtree.

_setRight

protected void _setRight(BinaryTree right)
Set the right subtree of this BinaryTree.
Parameters:
right - is a BinaryTree that will be the right subtree.

_setData

protected void _setData(Object obj)
Set the value that this BinaryTree holds.
Parameters:
data - is the value for the root of this BinaryTree.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

Copyright Information