E - The data type of the elements of this BinartSearchTree.
Must implement Comparable or inherit from a class that implements
Comparable.public class BinarySearchTree<E extends Comparable<? super E>> extends Object
| Constructor and Description |
|---|
BinarySearchTree() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E value)
Add the specified item to this Binary Search Tree if it is not already present.
|
E |
get(int kth)
Return the "kth" element in this Binary Search Tree.
|
List<E> |
getAll()
Return a list of all the elements in this Binary Search Tree.
|
List<E> |
getAllGreaterThan(E value)
Return a List with all values in this Binary Search Tree that are greater than
the parameter value.
|
List<E> |
getAllLessThan(E value)
Return a List with all values in this Binary Search Tree that are less than
the parameter value.
|
int |
height()
return the height of this Binary Search Tree.
|
boolean |
isPresent(E value)
Check to see if the specified element is in this Binary Search Tree.
|
boolean |
iterativeAdd(E data)
An add method that implements the add algorithm iteratively instead of recursively.
|
E |
max()
return the maximum value in this binary search tree.
|
E |
min()
return the minimum value in this binary search tree.
|
int |
numNodesAtDepth(int d)
Find the number of nodes in this tree at the specified depth.
|
void |
printTree()
Prints a vertical representation of this tree.
|
boolean |
remove(E value)
Remove a specified item from this Binary Search Tree if it is present.
|
int |
size()
Return how many elements are in this Binary Search Tree.
|
public boolean add(E value)
value - the value to add to the treepublic E get(int kth)
kth - indicates the rank of the element to getpublic List<E> getAll()
public List<E> getAllGreaterThan(E value)
value - the cutoff valuepublic List<E> getAllLessThan(E value)
value - the cutoff valuepublic int height()
public boolean isPresent(E value)
value - the value to look for in the treepublic boolean iterativeAdd(E data)
data - the item to be added to this treepublic E max()
public E min()
public int numNodesAtDepth(int d)
d - The target depth.public void printTree()
public boolean remove(E value)
value - the value to remove from the tree if presentpublic int size()