structure
Class BinarySearchTree

java.lang.Object
  extended by structure.AbstractStructure
      extended by structure.BinarySearchTree
All Implemented Interfaces:
OrderedStructure, Structure
Direct Known Subclasses:
SplayTree

public class BinarySearchTree
extends AbstractStructure
implements OrderedStructure

A binary search tree structure. This structure maintains data in an ordered tree. It does not keep the tree balanced, so performance may degrade if the tree height is not optimal.

See Also:
SplayTree, BinaryTree

Constructor Summary
BinarySearchTree()
          Constructs a binary search tree with no data
BinarySearchTree(Comparator alternateOrder)
          Constructs a binary search tree with no data
 
Method Summary
 void add(Object value)
          Add a (possibly duplicate) value to binary search tree
 void clear()
          Removes all data from the binary search tree
 boolean contains(Object value)
          Determines if the binary search tree contains a value
 Object get(Object value)
          Returns reference to value found within three.
 boolean isEmpty()
          Checks for an empty binary search tree
 Iterator iterator()
          Returns an iterator over the binary search tree.
 Object remove(Object value)
          Remove an value "equals to" the indicated value.
 int size()
          Determines the number of data values within the tree
 String toString()
          Returns a string representing tree
 
Methods inherited from class structure.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Structure
elements, values
 

Constructor Detail

BinarySearchTree

public BinarySearchTree()
Constructs a binary search tree with no data


BinarySearchTree

public BinarySearchTree(Comparator alternateOrder)
Constructs a binary search tree with no data

Method Detail

isEmpty

public boolean isEmpty()
Checks for an empty binary search tree

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True iff the tree contains no data

clear

public void clear()
Removes all data from the binary search tree

Specified by:
clear in interface Structure

size

public int size()
Determines the number of data values within the tree

Specified by:
size in interface Structure
Returns:
The number of nodes in the binary search tree

add

public void add(Object value)
Add a (possibly duplicate) value to binary search tree

Specified by:
add in interface Structure
Parameters:
val - A reference to non-null object

contains

public boolean contains(Object value)
Determines if the binary search tree contains a value

Specified by:
contains in interface Structure
Overrides:
contains in class AbstractStructure
Parameters:
val - The value sought. Should be non-null
Returns:
True iff the tree contains a value "equals to" sought value

get

public Object get(Object value)
Returns reference to value found within three. This method can be potentially dangerous if returned value is modified: if modification would change the relation of value to others within the tree, the consistency of the structure is lost Don't modify returned value

Parameters:
val - Value sought from within tree
Returns:
A value "equals to" value sought; otherwise null

remove

public Object remove(Object value)
Remove an value "equals to" the indicated value. Only one value is removed, and no guarantee is made concerning which of duplicate values are removed. Value returned is no longer part of the structure

Specified by:
remove in interface Structure
Parameters:
val - Value sought to be removed from tree
Returns:
Actual value removed from tree

iterator

public Iterator iterator()
Returns an iterator over the binary search tree. Iterator should not be used if tree is modified, as behavior may be unpredicatable Traverses elements using in-order traversal order

Specified by:
iterator in interface Structure
Returns:
An iterator over binary search tree
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()

toString

public String toString()
Returns a string representing tree

Overrides:
toString in class Object
Returns:
String representation of tree