package cse1030.recursion; /** * A binary search tree class. * *
* A binary search tree is a binary tree where values are stored in the tree * according to three rules: * *
subtreeRoot
. The
* element is inserted into the tree in a position that preserves the
* definition of a binary search tree.
*
* @param element
* the element to add to the subtree
* @param subtreeRoot
* the root of the subtree
*/
private static true
if the tree contains the given element,
* false
otherwise.
*
* @param element
* the element to search for
* @return true
if the tree contains the given element,
* false
otherwise
*/
public boolean contains(E element) {
return contains(element, this.root);
}
/**
* Returns true
if the subtree rooted at subtreeRoot
* contains the given element, false
otherwise.
*
* @param element
* the element to search for
* @param subtreeRoot
* the root of the subtree
* @return true
if the subtree rooted at subtreeRoot
* contains the given element, false
otherwise
*/
private static
* The string is made up of the elements stored in the tree separated
* by commas; the entire list of elements is enclosed in braces. The
* elements are in ascending sorted order.
*
* @see java.lang.Object#toString()
*
* @return a string representation of the tree
*/
@Override
public String toString() {
return "{" + toString(this.root) + "}";
}
/**
* Return a string representation of the subtree rooted at subtreeRoot
.
*
*
* The string is made up of the elements stored in the tree separated * by commas where the elements are in ascending sorted order. * *
* The string is generated using inorder processing of the subtree: * *
subtreeRoot.left
is computed
* subtreeRoot.data
is computed
* subtreeRoot.right
is computed
*
* The returned string is the concatenation of the three strings computed by the
* inorder processing of the subtree.
*
* @param subtreeRoot the root of the subtree
* @return the string representation of the subtree
*/
private static subtreeRoot
.
*
* @param subtreeRoot the root of the subtree
* @return the node in a subtree that is the predecessor to the root of the
* subtree, or null
if the root of the subtree has no predecessor
*/
public static subtreeRoot
.
*
* @param subtreeRoot the root of the subtree
* @return the node in a subtree that is the successor to the root of the
* subtree, or null
if the root of the subtree has no successor
*/
public static