scranton.tree
Interface PositionalBinaryTree

All Known Implementing Classes:
PositionalBinaryTreeViaRecTreeWStk

public interface PositionalBinaryTree

A class that represents a positional binary tree with a recursive binary tree and a stack. The stack maintains the path from the root (bottom of the stack) to the current subtree (top of the stack).


Method Summary
 java.lang.Object getNode()
          Replace the root of the current tree.
 void graft(PositionalBinaryTree Subtree)
          Grafts a tree to the current position of the tree, which must be empty.
 boolean isEmpty()
          Returns true if the current position is an empty tree.
 boolean isRoot()
          Returns true iff the current position is the root fo the tree.
 PositionalBinaryTree prune()
          Returns the subtree at the current position in the tree and makes the tree at the current position be empty.
 void setNode(java.lang.Object obj)
          Replace the current root with obj
 void toLeftSubtree()
          Navigates to the left subtree of the current tree.
 void toParent()
          Navigates to the parent of the current tree.
 void toRightSubtree()
          Navigates to the right subtree of the current tree.
 void toRoot()
          Navigates to the root of the tree structure.
 java.lang.String toString()
          Returns a string representation of the tree.
 

Method Detail

isEmpty

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

Returns:
True if the current position is an empty tree.

isRoot

public boolean isRoot()
Returns true iff the current position is the root fo the tree.

Returns:
True iff the current position is the root fo the tree

toRoot

public void toRoot()
Navigates to the root of the tree structure.


toParent

public void toParent()
Navigates to the parent of the current tree.


toLeftSubtree

public void toLeftSubtree()
Navigates to the left subtree of the current tree.


toRightSubtree

public void toRightSubtree()
Navigates to the right subtree of the current tree.


getNode

public java.lang.Object getNode()
Replace the root of the current tree.

Returns:
The original root of the current tree

setNode

public void setNode(java.lang.Object obj)
Replace the current root with obj

Parameters:
obj - New contents of the current root

graft

public void graft(PositionalBinaryTree Subtree)
Grafts a tree to the current position of the tree, which must be empty.

Parameters:
Subtree - Grafted to the current position in the tree

prune

public PositionalBinaryTree prune()
Returns the subtree at the current position in the tree and makes the tree at the current position be empty.

Returns:
The binary tree at the current position.

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.