All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class structure.BinarySearchTree

java.lang.Object
    |
    +----structure.BinarySearchTree

public class BinarySearchTree
extends Object
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 Index

 o BinarySearchTree()
Constructs a binary search tree with no data.

Method Index

 o add(Object)
Add a (possibly duplicate) value to binary search tree.
 o clear()
Removes all data from the binary search tree.
 o contains(Object)
Determines if the binary search tree contains a value.
 o elements()
Returns an iterator over the binary search tree.
 o get(Object)
Returns reference to value found within three.
 o isEmpty()
Checks for an empty binary search tree.
 o remove(Object)
Remove an value "equals to" the indicated value.
 o size()
Determines the number of data values within the tree.
 o toString()
Returns a string representing tree.

Constructors

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

Postcondition:
Constructs an empty binary search tree.

Methods

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

Postcondition:
Returns true iff the binary search tree is empty.

Returns:
True iff the tree contains no data.
 o clear
public void clear()
Removes all data from the binary search tree.

Postcondition:
Removes all elements from binary search tree

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

Postcondition:
Returns the number of elements in binary search tree

Returns:
The number of nodes in the binary search tree.
 o add
public void add(Object val)
Add a (possibly duplicate) value to binary search tree.

Postcondition:
Adds a value to binary search tree.

Parameters:
val - A reference to non-null object.
 o contains
public boolean contains(Object val)
Determines if the binary search tree contains a value.

Postcondition:
Returns true iff val is a value found within the tree

Parameters:
val - The value sought. Should be non-null.
Returns:
True iff the tree contains a value "equals to" sought value.
 o get
public Object get(Object val)
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

Postcondition:
Returns object found in tree, or null

Parameters:
val - Value sought from within tree.
Returns:
A value "equals to" value sought; otherwise null.
 o remove
public Object remove(Object val)
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.

Postcondition:
Removes one instance of val, if found

Parameters:
val - Value sought to be removed from tree.
Returns:
Actual value removed from tree.
 o elements
public Iterator elements()
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.

Postcondition:
Returns iterator to traverse BST

Returns:
An iterator over binary search tree.
 o toString
public String toString()
Returns a string representing tree.

Postcondition:
Generates a string representation of the BST

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

All Packages  Class Hierarchy  This Package  Previous  Next  Index