public interface Tree<E> extends Iterable<E>
Modifier and Type | Method and Description |
---|---|
Iterable<Position<E>> |
children(Position<E> p)
Returns an iterable collection of the Positions representing p's children.
|
boolean |
isEmpty()
Tests whether the tree is empty.
|
boolean |
isExternal(Position<E> p)
Returns true if Position p does not have any children.
|
boolean |
isInternal(Position<E> p)
Returns true if Position p has one or more children.
|
boolean |
isRoot(Position<E> p)
Returns true if Position p represents the root of the tree.
|
Iterator<E> |
iterator()
Returns an iterator of the elements stored in the tree.
|
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).
|
Iterable<Position<E>> |
positions()
Returns an iterable collection of the positions of the tree.
|
Position<E> |
root()
Returns the root Position of the tree (or null if tree is empty).
|
int |
size()
Returns the number of nodes in the tree.
|
Position<E> root()
Position<E> parent(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.Iterable<Position<E>> children(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.int numChildren(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.boolean isInternal(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.boolean isExternal(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.boolean isRoot(Position<E> p) throws IllegalArgumentException
p
- A valid Position within the treeIllegalArgumentException
- if p is not a valid Position for this tree.int size()
boolean isEmpty()