Class BST

java.lang.Object
  extended by BST

public class BST
extends Object

A binary search tree for Strings.


Constructor Summary
BST()
          Constructs an empty binary search tree.
 
Method Summary
 void clear()
          Makes the tree empty.
 boolean contains(String item)
          Searches for an item in the tree.
 int count()
          Counts the items.
 boolean delete(String item)
          Deletes item from the tree.
 int depth(String item)
          Finds an item's depth in the tree.
 int height()
          Finds the height of the tree.
 String inOrder()
          Returns in-order tree contents.
 boolean insert(String item)
          Inserts an item in the tree.
 boolean isEmpty()
          Returns true if the tree is empty.
 String postOrder()
          Returns post-order tree contents.
 String preOrder()
          Returns pre-order tree contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BST

public BST()
Constructs an empty binary search tree.

Method Detail

isEmpty

public boolean isEmpty()
Returns true if the tree is empty.


clear

public void clear()
Makes the tree empty.


contains

public boolean contains(String item)
Searches for an item in the tree.

Parameters:
item - the item to search for.
Returns:
true if tree contains a duplicate item, or false otherwise.

depth

public int depth(String item)
Finds an item's depth in the tree.

Parameters:
item - the item to find.
Returns:
-1 if item is not in the tree, 0 if item is in the root, or number of depths below root otherwise.

height

public int height()
Finds the height of the tree.

Returns:
the maximum depth of a node in the tree, -1 if tree is empty.

count

public int count()
Counts the items.

Returns:
count of items in the tree.

inOrder

public String inOrder()
Returns in-order tree contents.

Returns:
contents of tree in order.

preOrder

public String preOrder()
Returns pre-order tree contents.

Returns:
contents of tree pre-order.

postOrder

public String postOrder()
Returns post-order tree contents.

Returns:
contents of tree post-order.

insert

public boolean insert(String item)
Inserts an item in the tree. Does nothing if a duplicate item is already in the tree.

Parameters:
item - the item to insert.
Returns:
true if the item is inserted, or false if item is a duplicate.

delete

public boolean delete(String item)
Deletes item from the tree. Does nothing if item is not in the tree.

Parameters:
item - the item to delete.
Returns:
true if item has been deleted, or false if it is not in tree.