scranton.tree
Class PositionalBinaryTreeViaRecTreeWStk

java.lang.Object
  extended byscranton.tree.PositionalBinaryTreeViaRecTreeWStk
All Implemented Interfaces:
PositionalBinaryTree

public class PositionalBinaryTreeViaRecTreeWStk
extends java.lang.Object
implements 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).


Field Summary
protected  Stack Stk
          The stack contains the path from the root (bottom of the stack) to the current tree (top of the stack).
protected  RecursiveBinaryTreeViaLinear1 T
          The recursive binary tree used to represent the entire tree structure.
 
Constructor Summary
PositionalBinaryTreeViaRecTreeWStk()
          Construct an empty tree.
PositionalBinaryTreeViaRecTreeWStk(java.lang.Object root, PositionalBinaryTreeViaRecTreeWStk left, PositionalBinaryTreeViaRecTreeWStk right)
          Construct a tree with a root and two subtrees.
 
Method Summary
 PositionalBinaryTree factory()
           
 java.lang.Object getNode()
          Access 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 parenthesized string representation of the tree at the current position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

T

protected RecursiveBinaryTreeViaLinear1 T
The recursive binary tree used to represent the entire tree structure.


Stk

protected Stack Stk
The stack contains the path from the root (bottom of the stack) to the current tree (top of the stack).

Constructor Detail

PositionalBinaryTreeViaRecTreeWStk

public PositionalBinaryTreeViaRecTreeWStk()
Construct an empty tree.


PositionalBinaryTreeViaRecTreeWStk

public PositionalBinaryTreeViaRecTreeWStk(java.lang.Object root,
                                          PositionalBinaryTreeViaRecTreeWStk left,
                                          PositionalBinaryTreeViaRecTreeWStk right)
Construct a tree with a root and two subtrees.

Method Detail

isEmpty

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

Specified by:
isEmpty in interface PositionalBinaryTree
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.

Specified by:
isRoot in interface PositionalBinaryTree
Returns:
True iff the current position is the root fo the tree

toRoot

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

Specified by:
toRoot in interface PositionalBinaryTree

toParent

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

Specified by:
toParent in interface PositionalBinaryTree

toLeftSubtree

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

Specified by:
toLeftSubtree in interface PositionalBinaryTree

toRightSubtree

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

Specified by:
toRightSubtree in interface PositionalBinaryTree

getNode

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

Specified by:
getNode in interface PositionalBinaryTree
Returns:
The root of the current tree

setNode

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

Specified by:
setNode in interface PositionalBinaryTree
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.

Specified by:
graft in interface PositionalBinaryTree
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.

Specified by:
prune in interface PositionalBinaryTree
Returns:
The binary tree at the current position.

factory

public PositionalBinaryTree factory()

toString

public java.lang.String toString()
Returns a parenthesized string representation of the tree at the current position.

Specified by:
toString in interface PositionalBinaryTree
Returns:
A parenthesized string representation of a binary tree