Class bst

java.lang.Object
  |
  +--bst

public class bst
extends java.lang.Object


Constructor Summary
bst()
          Constructs a new binary search tree object, initializing the tree to be empty
 
Method Summary
 void addNode(int data)
          Adds a node containing the given number to the tree, keeping the tree ordered as a BST
 boolean contains(int value)
          Returns whether or not the tree contains a given value.
 boolean deleteNode(int data)
          Removes the node containing the given data item from the tree.
 void inOrder()
          Prints out the items in the tree using an in-order traversal
 void levelOrder()
          Prints out the items in the tree using a level-order traversal
 void postOrder()
          Prints out the items in the tree using a post-order traversal
 void preOrder()
          Prints out the items in the tree using a pre-order traversal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

bst

public bst()
Constructs a new binary search tree object, initializing the tree to be empty
Method Detail

addNode

public void addNode(int data)
Adds a node containing the given number to the tree, keeping the tree ordered as a BST
Parameters:
data - The number to be placed in the tree

contains

public boolean contains(int value)
Returns whether or not the tree contains a given value. This function must run in O(logN) time on a full and balanced tree, however it may run in O(n) time on a tree that is not balanced
Parameters:
value - The value to look for in the tree.
Returns:
True if value is contained in the tree, false if value is not contained in the tree.

deleteNode

public boolean deleteNode(int data)
Removes the node containing the given data item from the tree. You may assume that a given number will only appear once in the tree (i.e. no duplicates will be allowed in the tree).
Parameters:
data - The number to be removed from the tree
Returns:
True if the node was successfully deleted from the tree, false if it could not be deleted (e.g. if the given data value was not found in the tree).

inOrder

public void inOrder()
Prints out the items in the tree using an in-order traversal

postOrder

public void postOrder()
Prints out the items in the tree using a post-order traversal

preOrder

public void preOrder()
Prints out the items in the tree using a pre-order traversal

levelOrder

public void levelOrder()
Prints out the items in the tree using a level-order traversal