All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.roguewave.tools.v2-0.BinaryTree

java.lang.Object
   |
   +----com.roguewave.tools.v2-0.CollectionBase
           |
           +----com.roguewave.tools.v2-0.BinaryTree

public class BinaryTree
extends CollectionBase
implements Cloneable, Serializable
This class implements a binary search tree. The collection maintains elements in sorted order according to a Comparator object given at construction. Duplicates are allowed.

See Also:
Comparator, NumericCompare, StringCompare

Variable Index

 o comp_
The Comparator used to order elements of this tree
 o root_
The root node of this tree

Constructor Index

 o BinaryTree()
Creates an empty BinaryTree with a null comparator.
 o BinaryTree(Comparator)
Creates an empty BinaryTree.
 o BinaryTree(Node, Comparator)
Constructs a BinaryTree with the given root and comparator.

Method Index

 o balance()
Balances this BinaryTree.
 o balanceNodes(Vector, int, int)
Creates a balanced sorted binary tree from a vector of Nodes.
 o clear()
Removes all items from the collection.
 o clone()
Returns a clone of this BinaryTree.
 o contains(Object)
Returns true if the tree contains an element that compares equal to the given item.
 o elements()
Returns an enumeration of the elements in the BinaryTree.
 o find(Object)
Returns the first element in the tree that compares equal to the given item, or null if no such element.
 o height()
Returns the height of this BinaryTree by calculating the length of the longest path from the root to a leaf.
 o insert(Object)
Inserts the given item into the collection.
 o nodes()
Returns an Enumeration for an in-order traversal of the nodes of this tree
 o occurrencesOf(Object)
Returns the number of elements in the BinaryTree that compare equal to the given item.
 o remove(Object)
Removes and returns the first element in the collection that compares equal to the given item, or returns null if no such element.
 o removeAll(Object)
Removes all elements of the tree that compare equal to the given item.
 o setComparator(Comparator)
Set the Comparator.
 o toString()
Coverts this BinaryTree to a string.

Variables

 o root_
 protected Node root_
The root node of this tree

 o comp_
 protected Comparator comp_
The Comparator used to order elements of this tree

Constructors

 o BinaryTree
 public BinaryTree(Comparator comp)
Creates an empty BinaryTree.

Parameters:
comp - The object used to order the elements
 o BinaryTree
 public BinaryTree()
Creates an empty BinaryTree with a null comparator. The comparator must be set before adding any elements.

See Also:
setComparator
 o BinaryTree
 protected BinaryTree(Node aNode,
                      Comparator comp)
Constructs a BinaryTree with the given root and comparator.

Methods

 o clone
 public synchronized Object clone()
Returns a clone of this BinaryTree. Note that neither the Comparator object nor the elements of the tree themselves are cloned. The cloned tree will have the same node structure as the original.

Overrides:
clone in class Object
 o balance
 public synchronized void balance()
Balances this BinaryTree. Note that because this collection accepts duplicate entries, invoking this method cannot always result in a perfectly balanced tree.

 o clear
 public synchronized void clear()
Removes all items from the collection.

Overrides:
clear in class CollectionBase
 o contains
 public final boolean contains(Object item)
Returns true if the tree contains an element that compares equal to the given item.

Overrides:
contains in class CollectionBase
 o find
 public synchronized Object find(Object item)
Returns the first element in the tree that compares equal to the given item, or null if no such element.

Overrides:
find in class CollectionBase
 o height
 public synchronized int height()
Returns the height of this BinaryTree by calculating the length of the longest path from the root to a leaf. Note that an empty tree has height 0, while a tree with only a root with no children has height 1.

 o insert
 public synchronized Object insert(Object item)
Inserts the given item into the collection.

Returns:
item
Overrides:
insert in class CollectionBase
 o elements
 public synchronized Enumeration elements()
Returns an enumeration of the elements in the BinaryTree. Use the returned Enumeration object to visit each of the elements in turn.

Overrides:
elements in class CollectionBase
 o occurrencesOf
 public synchronized int occurrencesOf(Object item)
Returns the number of elements in the BinaryTree that compare equal to the given item.

Overrides:
occurrencesOf in class CollectionBase
 o remove
 public synchronized Object remove(Object item)
Removes and returns the first element in the collection that compares equal to the given item, or returns null if no such element.

Overrides:
remove in class CollectionBase
 o removeAll
 public synchronized int removeAll(Object item)
Removes all elements of the tree that compare equal to the given item.

Returns:
the number of items removed
Overrides:
removeAll in class CollectionBase
 o setComparator
 public boolean setComparator(Comparator comp)
Set the Comparator. The collection must be empty or this method will fail.

Returns:
true if the method is successfull, false otherwise.
 o toString
 public synchronized String toString()
Coverts this BinaryTree to a string. The string will have the form
   CompClass:[root [left, right]]
 
where CompClass is the string value of the Comparator and left and right recursively show the values of the children of the root. Thus, the returned string will show the node structure of the tree and will not show the elements in sorted sequence.

Overrides:
toString in class Object
 o balanceNodes
 protected Node balanceNodes(Vector nodes,
                             int left,
                             int right)
Creates a balanced sorted binary tree from a vector of Nodes.

Parameters:
nodes - A vector of Nodes in sorted order
left - Left index of Nodes to use
right - Right index of Nodes to use
Returns:
The root of the new tree
 o nodes
 protected Enumeration nodes()
Returns an Enumeration for an in-order traversal of the nodes of this tree


All Packages  Class Hierarchy  This Package  Previous  Next  Index