| Constructor and Description |
|---|
LinkedTree()
Creates an empty tree.
|
| Modifier and Type | Method and Description |
|---|---|
Position<E> |
addRoot(E e)
Adds a root node to an empty tree
|
java.lang.Iterable<Position<E>> |
children(Position<E> v)
Returns an iterable collection of the children of a node.
|
boolean |
isEmpty()
Returns whether the tree is empty.
|
boolean |
isExternal(Position<E> v)
Returns whether a node is external.
|
boolean |
isInternal(Position<E> v)
Returns whether a node is internal.
|
boolean |
isRoot(Position<E> v)
Returns whether a node is the root.
|
java.util.Iterator<E> |
iterator()
Returns an iterator of the elements stored at the nodes
|
Position<E> |
parent(Position<E> v)
Returns the parent of a node.
|
java.lang.Iterable<Position<E>> |
positions()
Returns an iterable collection of the tree nodes.
|
E |
replace(Position<E> v,
E o)
Replaces the element at a node.
|
Position<E> |
root()
Returns the root of the tree.
|
int |
size()
Returns the number of nodes in the tree.
|
void |
swapElements(Position<E> v,
Position<E> w)
Swap the elements at two nodes
|
public Position<E> addRoot(E e) throws NonEmptyTreeException
NonEmptyTreeExceptionpublic java.lang.Iterable<Position<E>> children(Position<E> v) throws InvalidPositionException
children in interface Tree<E>InvalidPositionExceptionpublic boolean isEmpty()
public boolean isExternal(Position<E> v) throws InvalidPositionException
isExternal in interface Tree<E>InvalidPositionExceptionpublic boolean isInternal(Position<E> v) throws InvalidPositionException
isInternal in interface Tree<E>InvalidPositionExceptionpublic boolean isRoot(Position<E> v) throws InvalidPositionException
isRoot in interface Tree<E>InvalidPositionExceptionpublic java.util.Iterator<E> iterator()
public Position<E> parent(Position<E> v) throws InvalidPositionException, BoundaryViolationException
parent in interface Tree<E>InvalidPositionExceptionBoundaryViolationExceptionpublic java.lang.Iterable<Position<E>> positions()
public E replace(Position<E> v, E o) throws InvalidPositionException
replace in interface Tree<E>InvalidPositionExceptionpublic Position<E> root() throws EmptyTreeException
root in interface Tree<E>EmptyTreeExceptionpublic int size()
public void swapElements(Position<E> v, Position<E> w) throws InvalidPositionException
InvalidPositionException