public class LinkedTree<E> extends AbstractTree<E>
| Modifier and Type | Class and Description |
|---|---|
protected static class |
LinkedTree.Node<E> |
| Constructor and Description |
|---|
LinkedTree() |
| Modifier and Type | Method and Description |
|---|---|
Position<E> |
addChild(Position<E> p,
E e) |
Position<E> |
addRoot(E e) |
Iterable<Position<E>> |
children(Position<E> p)
Returns an iterable collection of the Positions representing p's children.
|
int |
numChildren(Position<E> p)
Returns the number of children of Position p.
|
Position<E> |
parent(Position<E> p)
Returns the Position of p's parent (or null if p is root).
|
E |
pruneSubtree(Position<E> p) |
Position<E> |
root()
Returns the root Position of the tree (or null if tree is empty).
|
E |
set(Position<E> p,
E e)
Replaces the element at Position p with element e and returns the replaced element.
|
int |
size()
Returns the number of nodes in the tree.
|
protected LinkedTree.Node<E> |
validate(Position<E> p) |
breadthfirst, depth, height, isEmpty, isExternal, isInternal, isRoot, iterator, positions, postorder, preorderprotected LinkedTree.Node<E> validate(Position<E> p) throws IllegalArgumentException
IllegalArgumentExceptionpublic int size()
AbstractTreepublic Position<E> root()
Treepublic Position<E> parent(Position<E> p) throws IllegalArgumentException
Treep - A valid Position within the treeIllegalArgumentException - if p is not a valid Position for this tree.public int numChildren(Position<E> p) throws IllegalArgumentException
AbstractTreenumChildren in interface Tree<E>numChildren in class AbstractTree<E>p - A valid Position within the treeIllegalArgumentException - if p is not a valid Position for this tree.public Iterable<Position<E>> children(Position<E> p) throws IllegalArgumentException
Treep - A valid Position within the treeIllegalArgumentException - if p is not a valid Position for this tree.public Position<E> addRoot(E e) throws IllegalStateException
IllegalStateExceptionpublic Position<E> addChild(Position<E> p, E e) throws IllegalStateException
IllegalStateExceptionpublic E set(Position<E> p, E e) throws IllegalArgumentException
p - the relevant Positione - the new elementIllegalArgumentException - if p is not a valid Position for this tree.public E pruneSubtree(Position<E> p) throws IllegalArgumentException
IllegalArgumentException