|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--BinarySearchTree
Class BinarySearchTree defines a binary search tree data structure with Object-valued nodes. The class provides insert, remove, and find methods. See also the BinaryTree class. The difference between this BinarySearchTree class versus plain BinaryTree is that this class maintains the nodes in sorted order, per the standard binary search tree property.
This BinaryTree class uses the public class BinaryTreeNode as the definition of a tree node.
Constructor Summary | |
BinarySearchTree(BinaryTreeNode root)
Construct this with the given node as the root. |
Method Summary | |
BinaryTreeNode |
find(java.lang.Object value)
Return a pointer to the node containing the given value, using the O(log N) binary search tree algorithm. |
protected BinaryTreeNode |
find(java.lang.Object value,
BinaryTreeNode t)
Recursive work doer for find(Object). |
protected BinaryTreeNode |
findSmallest(BinaryTreeNode t)
Find the node with smallest value in the given subtree t. |
BinarySearchTree |
insert(java.lang.Object value)
Insert a new node containing the given value in the proper order position. |
protected BinaryTreeNode |
insert(java.lang.Object value,
BinaryTreeNode t)
Recursive work doer for insert(Object). |
BinarySearchTree |
remove(java.lang.Object value)
Remove the node containing the given value, if any, retaining the proper binary search tree structure. |
protected BinaryTreeNode |
remove(java.lang.Object value,
BinaryTreeNode t)
Recursive work doer for remove(Object). |
java.lang.String |
toString()
Convert this to a preorder string of the form: root left subtree ... |
protected java.lang.String |
toString(BinaryTreeNode t,
int indent)
Recursive work doer for toString(), converting the given node value to a string, preceded by indent spacing, followed by the recursive toString of the left and right subtrees. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public BinarySearchTree(BinaryTreeNode root)
Method Detail |
public BinarySearchTree insert(java.lang.Object value)
protected BinaryTreeNode insert(java.lang.Object value, BinaryTreeNode t)
public BinarySearchTree remove(java.lang.Object value)
protected BinaryTreeNode remove(java.lang.Object value, BinaryTreeNode t)
protected BinaryTreeNode findSmallest(BinaryTreeNode t)
public BinaryTreeNode find(java.lang.Object value)
protected BinaryTreeNode find(java.lang.Object value, BinaryTreeNode t)
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String toString(BinaryTreeNode t, int indent)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |