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

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

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

clear()
 Removes all data from the binary search tree.

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

elements()
 Returns an iterator over the binary search tree.

get(Object)
 Returns reference to value found within three.

isEmpty()
 Checks for an empty binary search tree.

remove(Object)
 Remove an value "equals to" the indicated value.

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

toString()
 Returns a string representing tree.
BinarySearchTree
public BinarySearchTree()
 Constructs a binary search tree with no data.
 Postcondition:
 Constructs an empty binary search tree.
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.
clear
public void clear()
 Removes all data from the binary search tree.
 Postcondition:
 Removes all elements from binary search tree
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.
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 nonnull object.
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 nonnull.
 Returns:
 True iff the tree contains a value "equals to" sought value.
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.
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.
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 inorder traversal order.
 Postcondition:
 Returns iterator to traverse BST
 Returns:
 An iterator over binary search tree.
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