net.datastructures
Interface Tree<E>

All Known Subinterfaces:
BinaryTree<E>, CompleteBinaryTree<E>
All Known Implementing Classes:
ArrayListCompleteBinaryTree, AVLTree, BinarySearchTree, LinkedBinaryTree, LinkedTree, RBTree

public interface Tree<E>

An interface for a tree where nodes can have an arbitrary number of children.

Author:
Michael Goodrich

Method Summary
 java.lang.Iterable<Position<E>> children(Position<E> v)
          Returns an iterable collection of the children of a given node.
 boolean isEmpty()
          Returns whether the tree is empty.
 boolean isExternal(Position<E> v)
          Returns whether a given node is external.
 boolean isInternal(Position<E> v)
          Returns whether a given node is internal.
 boolean isRoot(Position<E> v)
          Returns whether a given node is the root of the tree.
 java.util.Iterator<E> iterator()
          Returns an iterator of the elements stored in the tree.
 Position<E> parent(Position<E> v)
          Returns the parent of a given node.
 java.lang.Iterable<Position<E>> positions()
          Returns an iterable collection of the the nodes.
 E replace(Position<E> v, E e)
          Replaces the element stored at a given node.
 Position<E> root()
          Returns the root of the tree.
 int size()
          Returns the number of nodes in the tree.
 

Method Detail

size

int size()
Returns the number of nodes in the tree.


isEmpty

boolean isEmpty()
Returns whether the tree is empty.


iterator

java.util.Iterator<E> iterator()
Returns an iterator of the elements stored in the tree.


positions

java.lang.Iterable<Position<E>> positions()
Returns an iterable collection of the the nodes.


replace

E replace(Position<E> v,
          E e)
          throws InvalidPositionException
Replaces the element stored at a given node.

Throws:
InvalidPositionException

root

Position<E> root()
                 throws EmptyTreeException
Returns the root of the tree.

Throws:
EmptyTreeException

parent

Position<E> parent(Position<E> v)
                   throws InvalidPositionException,
                          BoundaryViolationException
Returns the parent of a given node.

Throws:
InvalidPositionException
BoundaryViolationException

children

java.lang.Iterable<Position<E>> children(Position<E> v)
                                         throws InvalidPositionException
Returns an iterable collection of the children of a given node.

Throws:
InvalidPositionException

isInternal

boolean isInternal(Position<E> v)
                   throws InvalidPositionException
Returns whether a given node is internal.

Throws:
InvalidPositionException

isExternal

boolean isExternal(Position<E> v)
                   throws InvalidPositionException
Returns whether a given node is external.

Throws:
InvalidPositionException

isRoot

boolean isRoot(Position<E> v)
               throws InvalidPositionException
Returns whether a given node is the root of the tree.

Throws:
InvalidPositionException