dataStructures
Class LinkedBinaryTree

java.lang.Object
  |
  +--dataStructures.LinkedBinaryTree
Direct Known Subclasses:
BinarySearchTree

public class LinkedBinaryTree
extends java.lang.Object
implements BinaryTree


Constructor Summary
LinkedBinaryTree()
           
 
Method Summary
static void add1(BinaryTreeNode t)
          visit method to count nodes
 int height()
           
 void inOrder(java.lang.reflect.Method visit)
          inorder traversal
 void inOrderOutput()
          output elements in inorder
 boolean isEmpty()
           
 void levelOrder(java.lang.reflect.Method visit)
          level order traversal
 void levelOrderOutput()
          output elements in level order
static void main(java.lang.String[] args)
          test program
 void makeTree(java.lang.Object root, java.lang.Object left, java.lang.Object right)
          set this to the tree with the given root and subtrees CAUTION: does not clone left and right
static void output(BinaryTreeNode t)
          visit method that outputs element
 void postOrder(java.lang.reflect.Method visit)
          postorder traversal
 void postOrderOutput()
          output elements in postorder
 void preOrder(java.lang.reflect.Method visit)
          preorder traversal
 void preOrderOutput()
          output elements in preorder
 BinaryTree removeLeftSubtree()
          remove the left subtree
 BinaryTree removeRightSubtree()
          remove the right subtree
 java.lang.Object root()
           
 int size()
          count number of nodes in tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinkedBinaryTree

public LinkedBinaryTree()
Method Detail

output

public static void output(BinaryTreeNode t)
visit method that outputs element

add1

public static void add1(BinaryTreeNode t)
visit method to count nodes

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface BinaryTree
Returns:
true iff tree is empty

root

public java.lang.Object root()
Specified by:
root in interface BinaryTree
Returns:
root element if tree is not empty

makeTree

public void makeTree(java.lang.Object root,
                     java.lang.Object left,
                     java.lang.Object right)
set this to the tree with the given root and subtrees CAUTION: does not clone left and right
Specified by:
makeTree in interface BinaryTree

removeLeftSubtree

public BinaryTree removeLeftSubtree()
remove the left subtree
Specified by:
removeLeftSubtree in interface BinaryTree
Returns:
removed subtree
Throws:
java.lang.IllegalArgumentException - when tree is empty

removeRightSubtree

public BinaryTree removeRightSubtree()
remove the right subtree
Specified by:
removeRightSubtree in interface BinaryTree
Returns:
removed subtree
Throws:
java.lang.IllegalArgumentException - when tree is empty

preOrder

public void preOrder(java.lang.reflect.Method visit)
preorder traversal
Specified by:
preOrder in interface BinaryTree

inOrder

public void inOrder(java.lang.reflect.Method visit)
inorder traversal
Specified by:
inOrder in interface BinaryTree

postOrder

public void postOrder(java.lang.reflect.Method visit)
postorder traversal
Specified by:
postOrder in interface BinaryTree

levelOrder

public void levelOrder(java.lang.reflect.Method visit)
level order traversal
Specified by:
levelOrder in interface BinaryTree

preOrderOutput

public void preOrderOutput()
output elements in preorder

inOrderOutput

public void inOrderOutput()
output elements in inorder

postOrderOutput

public void postOrderOutput()
output elements in postorder

levelOrderOutput

public void levelOrderOutput()
output elements in level order

size

public int size()
count number of nodes in tree

height

public int height()
Returns:
tree height

main

public static void main(java.lang.String[] args)
test program