All Packages Class Hierarchy This Package Previous Next Index
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.
Position
subtreeRoot and all its children are removed from this
tree and replaced with a new external node with a null element.
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.
public abstract void expandExternal(Position mustBeExternal) throws InvalidPositionException, InvalidContainerException
null
objects.
BinaryTree
public abstract 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.
public abstract 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
is of a type
not accepted by this container or null
.
public abstract void link(Position mustBeExternal, BinaryTree newSubtree) throws InvalidPositionException, InvalidContainerException, InvalidArgumentException
subtreeRoot
is of a type
not accepted by this container or null
.
newSubtree
is the same
tree that link
is called on.
public abstract 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.
BinaryTree
on which the
method is called
BinaryTree
, with subtreeRoot as its root
subtreeRoot
is of a type
not accepted by this container or null
.
newSubtree
is the same
All Packages Class Hierarchy This Package Previous Next Index