datastructures

net.datastructures
Interface Tree

All Known Subinterfaces:
BinaryTree, CompleteBinaryTree
All Known Implementing Classes:
LinkedBinaryTree, VectorCompleteBinaryTree

public interface Tree

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

Author:
Michael Goodrich

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

Method Detail

size

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


isEmpty

public boolean isEmpty()
Returns whether the tree is empty.


elements

public Iterator elements()
Return an iterator of the elements stored in the tree.


positions

public Iterator positions()
Returns an iterator of the nodes stored in the tree.


replace

public Object replace(Position v,
                      Object e)
               throws InvalidPositionException
Replaces the element stored at a given node.

Throws:
InvalidPositionException

root

public Position root()
              throws EmptyTreeException
Returns the root of the tree.

Throws:
EmptyTreeException

parent

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

Throws:
InvalidPositionException
BoundaryViolationException

children

public Iterator children(Position v)
                  throws InvalidPositionException
Returns an iterator of the children of a given node.

Throws:
InvalidPositionException

isInternal

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

Throws:
InvalidPositionException

isExternal

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

Throws:
InvalidPositionException

isRoot

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

Throws:
InvalidPositionException

datastructures