|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Interface for a binary tree that can be modified. Note that binary
trees are specified to start with a single external node with a null
element, so no generic insert(.) method is needed here; every
conceivable binary tree (except one with no nodes at all) can be built up
from the methods of this interface. In addition, because the splice
methods (link and replaceSubtree) invalidate containers. Any class
implementing BinaryTree must throw an
InvalidContainerException from all methods if the container has
been invalidated.
For a binary tree, methods Container.elements() and
PositionalContainer.positions() are guaranteed to return
enumerations in preorder order.
| Method Summary | |
BinaryTree |
cut(Position subtreeRoot)
Position subtreeRoot and all its children are removed from this
tree and replaced with a new external node with a null element. |
void |
expandExternal(Position mustBeExternal)
The external position specified is transformed into an internal, and it gains two children. |
Position |
leftChild(Position p)
Gets the left child of p |
void |
link(Position mustBeExternal,
BinaryTree newSubtree)
Position mustBeExternal is removed from the tree. |
void |
removeAboveExternal(Position mustBeExternal)
The parent of Position mustBeExternal is deleted, and the
sibling subtree of mustBeExternal takes the parent's place as the
left/right child of the parent's parent. |
BinaryTree |
replaceSubtree(Position subtreeRoot,
BinaryTree newSubtree)
Swaps a subtree of the tree on which the method is called with a "subtree" passed in. |
Position |
rightChild(Position p)
Gets the right child of p. |
Position |
sibling(Position p)
Gets the sibling Position of the
Position passed in. |
| Methods inherited from interface jdsl.InspectableTree |
children,
isExternal,
isInternal,
isRoot,
parent,
root,
siblings |
| Methods inherited from interface jdsl.PositionalContainer |
positions,
replace,
swap |
| Methods inherited from interface jdsl.Container |
elements,
isEmpty,
newContainer,
size |
| Method Detail |
public Position leftChild(Position p)
throws InvalidPositionException,
BoundaryViolationException,
InvalidContainerException
p - Any node of the tree
public Position rightChild(Position p)
throws InvalidPositionException,
BoundaryViolationException,
InvalidContainerException
p - Any node of the tree
public Position sibling(Position p)
throws InvalidPositionException,
BoundaryViolationException,
InvalidContainerException
Position of the
Position passed in.otherChild - Any node of the tree
public void expandExternal(Position mustBeExternal)
throws InvalidPositionException,
InvalidContainerException
null objects.mustBeExternal - A position which must be an external
position in the BinaryTree
public void removeAboveExternal(Position mustBeExternal)
throws InvalidPositionException,
BoundaryViolationException,
InvalidContainerException
Position mustBeExternal is deleted, and the
sibling subtree of mustBeExternal takes the parent's place as the
left/right child of the parent's parent. The external position
specified is also deleted.mustBeExternal - A position which must be an external
position in the BinaryTree
public BinaryTree cut(Position subtreeRoot)
throws InvalidPositionException,
InvalidContainerException
Position subtreeRoot and all its children are removed from this
tree and replaced with a new external node with a null element.
They are packaged in a new binary tree and returned; all positions
and elements are still valid, although some of them have a
different container after the operation.subtreeRoot - The position above which to make the cutsubtreeRoot is of a type
not accepted by this container or null.
public void link(Position mustBeExternal,
BinaryTree newSubtree)
throws InvalidPositionException,
InvalidContainerException,
InvalidArgumentException
mustBeExternal - The external node to replace with the new
subtreenewSubtree - The subtree to link insubtreeRoot is of a type
not accepted by this container or null.newSubtree is the same
tree that link is called on.
public BinaryTree replaceSubtree(Position subtreeRoot,
BinaryTree newSubtree)
throws InvalidPositionException,
InvalidContainerException,
InvalidArgumentException
Position subtreeRoot specifies a subtree of the
tree on which this method is called. That subtree is removed from the tree,
and newSubtree is linked in in its place. A new tree, whose
root is the position subtreeRoot, is returned to the user (this
tree corresponds exactly to the removed subtree). Note that a new
BinaryTree is created to hold this removed subtree.
Note that link(.) and cut(.) can both be implemented in terms of
this method.subtreeRoot - Any position in the BinaryTree on which the
method is callednewSubtree - The tree that will replace the tree rooted at
subtreeRootBinaryTree, with subtreeRoot as its rootsubtreeRoot is of a type
not accepted by this container or null.newSubtree is the same
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||