|
net.datastructures - version 5.0 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.datastructures.LinkedTree<E>
public class LinkedTree<E>
A linked class for a tree where nodes have an arbitrary number of children. //end#fragment Tree
| Field Summary | |
|---|---|
protected TreePosition<E> |
root
|
protected int |
size
|
| Constructor Summary | |
|---|---|
LinkedTree()
Creates an empty tree. |
|
| Method Summary | |
|---|---|
Position<E> |
addRoot(E e)
Adds a root node to an empty tree |
protected TreePosition<E> |
checkPosition(Position<E> v)
If v is a good tree node, cast to TreePosition, else throw exception |
Iterable<Position<E>> |
children(Position<E> v)
Returns an iterable collection of the children of a node. |
protected TreePosition<E> |
createNode(E element,
TreePosition<E> parent,
PositionList<Position<E>> children)
Creates a new tree 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. |
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. |
Iterable<Position<E>> |
positions()
Returns an iterable collection of the tree nodes. |
protected void |
preorderPositions(Position<E> v,
PositionList<Position<E>> pos)
Creates a list storing the the nodes in the subtree of a node, ordered according to the preorder traversal of the subtree. |
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 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected TreePosition<E> root
protected int size
| Constructor Detail |
|---|
public LinkedTree()
| Method Detail |
|---|
public int size()
size in interface Tree<E>public boolean isEmpty()
isEmpty in interface Tree<E>
public boolean isInternal(Position<E> v)
throws InvalidPositionException
isInternal in interface Tree<E>InvalidPositionException
public boolean isExternal(Position<E> v)
throws InvalidPositionException
isExternal in interface Tree<E>InvalidPositionException
public boolean isRoot(Position<E> v)
throws InvalidPositionException
isRoot in interface Tree<E>InvalidPositionException
public Position<E> root()
throws EmptyTreeException
root in interface Tree<E>EmptyTreeException
public Position<E> parent(Position<E> v)
throws InvalidPositionException,
BoundaryViolationException
parent in interface Tree<E>InvalidPositionException
BoundaryViolationException
public Iterable<Position<E>> children(Position<E> v)
throws InvalidPositionException
children in interface Tree<E>InvalidPositionExceptionpublic Iterable<Position<E>> positions()
positions in interface Tree<E>public Iterator<E> iterator()
iterator in interface Tree<E>
public E replace(Position<E> v,
E o)
throws InvalidPositionException
replace in interface Tree<E>InvalidPositionException
public Position<E> addRoot(E e)
throws NonEmptyTreeException
NonEmptyTreeException
public void swapElements(Position<E> v,
Position<E> w)
throws InvalidPositionException
InvalidPositionException
protected TreePosition<E> checkPosition(Position<E> v)
throws InvalidPositionException
InvalidPositionException
protected TreePosition<E> createNode(E element,
TreePosition<E> parent,
PositionList<Position<E>> children)
protected void preorderPositions(Position<E> v,
PositionList<Position<E>> pos)
throws InvalidPositionException
InvalidPositionException
|
net.datastructures - version 5.0 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||