scranton.tree
Interface RecursiveBinaryTree

All Known Implementing Classes:
RecursiveBinaryTreeViaLinear1

public interface RecursiveBinaryTree

This interface describes one interpretation of an object oriented versions of the recursive binary tree found in McCarthey's LISP. Specification: a binary tree, T, is (1) empty, T = (), or (2) T = (r,(L,R)) where r is the root of the tree and L and R are (possibly empty) binary trees.


Method Summary
 java.lang.Object getRoot()
          Returns a reference to the root of the current tree.
 void graft(RecursiveBinaryTree T)
          Replace the current tree by T.
 boolean isEmpty()
          Returns true if and only if the current tree is empty.
 RecursiveBinaryTree leftSubtree()
          Returns a reference to the left subtree of the current tree.
 RecursiveBinaryTree prune()
          Return reference to the current tree, then make current tree empty.
 RecursiveBinaryTree rightSubtree()
          Returns a reference to the right subtree of the current tree.
 void setRoot(java.lang.Object obj)
          Modify the root of the current tree.
 java.lang.String toString()
          Returns a string representation of the tree.
 

Method Detail

isEmpty

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

Returns:
true iff this==()

leftSubtree

public RecursiveBinaryTree leftSubtree()
Returns a reference to the left subtree of the current tree. Pre: T/=(), T=(r,(L,R))

Returns:
Reference to the leftSubtree of the current tree

rightSubtree

public RecursiveBinaryTree rightSubtree()
Returns a reference to the right subtree of the current tree. Pre: T/=(), T=(r,(L,R))

Returns:
Reference to the rightSubtree of the current tree

getRoot

public java.lang.Object getRoot()
Returns a reference to the root of the current tree. Pre: T/=(), T=(r,(L,R)) h

Returns:
Reference to the root of the tree

setRoot

public void setRoot(java.lang.Object obj)
Modify the root of the current tree. Pre: T/=(), T=(r,(L,R)) Post: T'=(obj,(L,R))

Parameters:
obj - The new root of the current tree

graft

public void graft(RecursiveBinaryTree T)
Replace the current tree by T. Pre: this = () Post: this'=T, T'=()

Parameters:
T - becomes the current tree

prune

public RecursiveBinaryTree prune()
Return reference to the current tree, then make current tree empty. Post: T'=()

Returns:
The current tree

toString

public java.lang.String toString()
Returns a string representation of the tree. The string representation is "[]" for an empty tree, otherwise "[leftsubtree \t root \t rightsubtree]"

Returns:
The string representation of the tree.