|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectBinaryTreeBasis<T>
BinarySearchTree<T,KT>
public class BinarySearchTree<T extends KeyedItem<KT>,KT extends java.lang.Comparable<? super KT>>
| Constructor Summary | |
|---|---|
BinarySearchTree()
The default constructor for BinarySearchTree initializes the
BinaryTree to be empty. |
|
BinarySearchTree(T rootItem)
This constructor for BinarySearchTree initializes the BinarySearchTree to
have a root containing the specified data item. |
|
| Method Summary | |
|---|---|
void |
balance()
This method is used to balance the BinarySearchTree. |
TreeNode<T> |
balance(java.lang.Object[] arr,
int first,
int last)
This method is the recursive method to balance the BinarySearchTree. |
void |
delete(KT searchKey)
This is the public method used to delete a data item from the BinarySearchTree based
on the specified searchKey. |
void |
delete(T item)
This is the public method used to delete a data item from the BinarySearchTree based
on the specified data item. |
int |
height()
This is the method the user calls to find the height of the BinarySearchTree. |
int |
height(TreeNode<T> root)
This method is used to obtain the height of the BinarySearchTree. |
void |
insert(T newItem)
This is the public method used to insert a new data item into the BinarySearchTree. |
boolean |
isBalanced()
This is the method the user calls to find out if the BinarySearchTree is balanced. |
boolean |
isBalanced(TreeNode<T> root)
This method is used to check if the BinarySearchTree rooted at the specified node
is balanced. |
T |
retrieve(KT searchKey)
This is the public method used to retrieve a data item from the BinarySearchTree based
on the specified searchKey. |
void |
setRootItem(T newItem)
This method will override the inherited method from BinaryTree and disable its operation |
| Methods inherited from class BinaryTreeBasis |
|---|
getRoot, getRootItem, isEmpty, makeEmpty, setRoot |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BinarySearchTree()
BinarySearchTree initializes the
BinaryTree to be empty.
public BinarySearchTree(T rootItem)
BinarySearchTree initializes the BinarySearchTree to
have a root containing the specified data item.
rootItem - The data item that will be contained by the root of this BinaryTree| Method Detail |
|---|
public void setRootItem(T newItem)
throws java.lang.UnsupportedOperationException
BinaryTree and disable its operation
setRootItem in class BinaryTreeBasis<T extends KeyedItem<KT>>newItem - the data item to be contained in the root node.
This - method always throws the UnsupportedOperationException
java.lang.UnsupportedOperationExceptionpublic void insert(T newItem)
BinarySearchTree.
newItem - The data item to be inserted into the BinarySearchTree.public T retrieve(KT searchKey)
BinarySearchTree based
on the specified searchKey.
searchKey - The searchKey of the data item the user wishes to retrieve from the BinarySearchTree.
public void delete(KT searchKey)
throws TreeException
BinarySearchTree based
on the specified searchKey.
searchKey - The searchKey of the data item the user wishes to delete from the BinarySearchTree.
TreeException
public void delete(T item)
throws TreeException
BinarySearchTree based
on the specified data item.
item - The data item the user wishes to delete from the BinarySearchTree.
TreeExceptionpublic boolean isBalanced()
BinarySearchTree is balanced.
This method will call the recursive method public boolean isBalanced(TreeNode
to find the answer.
true if the BinarySearchTree is balanced, false otherwise.public int height()
BinarySearchTree.
This method will call the recursive method public int height(TreeNode
to calculate the height.
BinarySearchTree.public void balance()
BinarySearchTree.
This method will call the recursive method public TreeNode
to balance the tree.
public boolean isBalanced(TreeNode<T> root)
BinarySearchTree rooted at the specified node
is balanced.
root - The root node of the BinarySearchTree that is being checked for
balance.
true if the BinarySearchTree is balanced, false otherwise.public int height(TreeNode<T> root)
BinarySearchTree.
root - The root node of the BinarySearchTree for which we are measuring
the height.
BinarySearchTree.
public TreeNode<T> balance(java.lang.Object[] arr,
int first,
int last)
BinarySearchTree.
arr - An array containing all the data items for the BinarySearchTree in sorted order.first - The first index of the array.last - The last index of the array.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||