|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface BinaryForest<E>
The BinaryForest
interface extends the Forest
interface. It defines a forest which contains only binary trees. In this
implementation. A node can have 0 children (it is called a leaf), 1 child
or 2 children. To each child is assigned a position, left or right, so for
each node, we have one or zero left child and one or zero right child.
Here is an example of use of a binary forest. We have a recursive algorithm
for displaying all the trees of a binary forest.
static void displayRecBinaryForest(BinaryForestAll implementations of that interface should throw anf,Position p, int depth){ if(f.childLeft(p)!= null){ displayRecBinaryForest(f,f.childLeft(p),depth+1); } System.out.println(createXSpaces(depth)+p.element()); if(f.childRight(p)!= null){ displayRecBinaryForest(f,f.childRight(p),depth+1); } } public static void displayBinaryForest(BinaryForest f){ System.out.println("--------"); for(Position root : f.roots()){ displayRecBinaryForest(f,root,0); System.out.println("--------"); } }
UnsupportedOperationException
when the following methods are
executed: link
, linkAfter
and
linkBefore
.
Method Summary | |
---|---|
Position<E> |
childLeft(Position<?> parent)
Access the left child of a given node (the parent ). |
Position<E> |
childRight(Position<?> parent)
Access the right child of a given node (the parent ). |
void |
linkLeft(Position<?> parent,
Position<?> child)
Creates a link (parent-child relationship) between a node, the parent , and another node, the child
The child should not have any parent, i.e. |
void |
linkRight(Position<?> parent,
Position<?> child)
Creates a link (parent-child relationship) between a node, the parent , and another node, the child
The child should not have any parent, i.e. |
Methods inherited from interface ch.bfh.algo.Forest |
---|
children, cut, link, linkAfter, linkBefore, parent, roots |
Methods inherited from interface ch.bfh.algo.Container |
---|
delete, element, encloses, insert, positionIterator, replace, swap |
Methods inherited from interface java.util.Collection |
---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
Method Detail |
---|
Position<E> childLeft(Position<?> parent) throws InvalidAccessorException
parent
).
parent
- the node of which we want the left child
parent
InvalidAccessorException
- if the position is not a
valid node of this forest.Position<E> childRight(Position<?> parent) throws InvalidAccessorException
parent
).
parent
- the node of which we want the right child
parent
InvalidAccessorException
- if the position is not a
valid node of this forest.void linkLeft(Position<?> parent, Position<?> child) throws InvalidAccessorException
parent
, and another node, the child
The child should not have any parent, i.e. it is a root.
parent
- The node receiving a new left childchild
- The node becoming the new left child
InvalidAccessorException
- if the position is not a
valid node of this forest.void linkRight(Position<?> parent, Position<?> child) throws InvalidAccessorException
parent
, and another node, the child
The child should not have any parent, i.e. it is a root.
parent
- The node receiving a new left childchild
- The node becoming the new left child
InvalidAccessorException
- if the position is not a
valid node of this forest.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |