/*
* Created on Apr 8, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author kim
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.util.Iterator;
import structure.AbstractIterator;
public class EmptyBinaryTree implements BinaryTreeInterface{
protected EmptyBinaryTree() {}
public BinaryTreeInterface left() {
return EMPTY;
}
/**
* Get right subtree of current node
*
* @post Returns reference to right subtree, or null
*
* @return The right subtree of this node
*/
public BinaryTreeInterface right() {
return EMPTY;
}
/**
* Get reference to parent of this node
*
* @post Returns reference to parent node, or null
*
* @return Reference to parent of this node
*/
public BinaryTreeInterface parent() {
return EMPTY;
}
/**
* Update the left subtree of this node. Parent of the left subtree is
* updated consistently. Existing subtree is detached
*
* @post Sets left subtree to newLeft re-parents newLeft if not null
*
* @param newLeft
* The root of the new left subtree
*/
public void setLeft(BinaryTreeInterface newLeft) { }
/**
* Update the right subtree of this node. Parent of the right subtree is
* updated consistently. Existing subtree is detached
*
* @post Sets left subtree to newRight re-parents newRight if not null
*
* @param newRight
* A reference to the new right subtree of this node
*/
public void setRight(BinaryTreeInterface newRight){}
/* (non-Javadoc)
* @see BinaryTreeInterface#setParent(BinaryTreeInterface)
*/
public void setParent(BinaryTreeInterface newParent) {}
/**
* Returns the number of descendants of node
*
* @post Returns the size of the subtree
*
* @return Size of subtree
*/
public int size() {
return 0;
}
/**
* Returns reference to root of tree containing n
*
* @post Returns the root of the tree node n
*
* @return Root of tree
*/
public BinaryTreeInterface root() {
return EMPTY;
}
/**
* Returns height of node in tree. Height is maximum path length to
* descendant
*
* @post Returns the height of a node in its tree
*
* @return The height of the node in the tree
*/
public int height(){
return -1;
}
/**
* Compute the depth of a node. The depth is the path length from node to
* root
*
* @post Returns the depth of a node in the tree
*
* @return The path length to root of tree
*/
public int depth() {
return -1;
}
/**
* Returns true if tree is full. A tree is full if adding a node to tree
* would necessarily increase its height
*
* @post Returns true iff the tree rooted at node is full
*
* @return True iff tree is full
*/
public boolean isFull() {
return true;
}
/**
* Returns true if tree is empty. @post Returns true iff the tree rooted at
* node is empty
*
* @return True iff tree is empty
*/
public boolean isEmpty() {
return true;
}
/**
* Return whether tree is complete. A complete tree has minimal height and
* any holes in tree would appear in last level to right.
*
* @post Returns true iff the tree rooted at node is complete
*
* @return True iff the subtree is complete
*/
public boolean isComplete() {
return true;
}
/**
* Return true iff the tree is height balanced. A tree is height balanced
* iff at every node the difference in heights of subtrees is no greater
* than one
*
* @post Returns true iff the tree rooted at node is balanced
*
* @return True if tree is height balanced
*/
public boolean isBalanced(){
return true;
}
/**
* Generate an in-order iterator of subtree
*
* @post Returns an in-order iterator of the elements
*
* @return In-order iterator on subtree rooted at this
*/
public Iterator iterator(){
return inorderIterator();
}
/**
* Return an iterator to traverse nodes of subtree in-order
*
* @post The elements of the binary tree rooted at node are traversed in
* preorder
*
* @return AbstractIterator to traverse subtree
*/
public AbstractIterator preorderIterator(){
return new BTPreorderIterator(this);
}
/**
* Return an iterator to traverse the elements of subtree in-order
*
* @post The elements of the binary tree rooted at node node are traversed
* in inorder
*
* @return An in-order iterator over descendants of node
*/
public AbstractIterator inorderIterator(){
return new BTInorderIterator(this);
}
/**
* Return an iterator to traverse the elements of subtree in post-order
*
* @pre None @post The elements of the binary tree rooted at node node are
* traversed in postorder
*
* @return An iterator that traverses descendants of node in postorder
*/
public AbstractIterator postorderIterator(){
return new BTPostorderIterator(this);
}
/**
* Method to return a level-order iterator of subtree
*
* @pre None @post The elements of the binary tree rooted at node node are
* traversed in levelorder
*
* @return An iterator to traverse subtree in level-order
*/
public AbstractIterator levelorderIterator(){
return new BTLevelorderIterator(this);
}
/**
* Determine if this node is a left child
*
* @post Returns true if this is a left child of parent
*
* @return True iff this node is a left child of parent
*/
public boolean isLeftChild() {
return false;
}
/**
* Determine if this node is a right child
*
* @post Returns true if this is a right child of parent
*
* @return True iff this node is a right child of parent
*/
public boolean isRightChild() {
return false;
}
/**
* Returns value associated with this node
*
* @post Returns value associated with this node
*
* @return The node's value
*/
public Object value() {
return null;
}
/**
* Set's value associated with this node
*
* @post Sets the value associated with this node
*
* @param value
* The new value of this node
*/
public void setValue(Object value){};
/**
* Returns a string representing the tree rooted at this node.
* WARNING this can be a very long string.
*
* @return A string representing the tree rooted at this node.
*/
public String treeString(){
return "";
}
public String toString() {
return "";
}
}