|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nz.ac.waikato.jdsl.core.algo.traversals.EulerTour
public abstract class EulerTour
The EulerTour algorithm is a tree traversal that can be informally described as a walk around tree T, where we start by going from the root towards its left child, viewing the edges of T as being "walls" that we always keep to our left.
Each internal node v of T with c children is seen c+1 times:
1. "on the left" (before the Euler tour of v's left subtree
2. "between children" (between the Euler tours of the subtrees)
3. "on the right" (after the Euler tour of v's right subtree)
Each external node of T is seen one time.
This algorithm object uses the template method pattern.
To do anything useful, at least one of the methods
visitFirst(Pos), visitBetweenChildren(Pos), and visitLast(Pos),
and visitExternal(Pos) will need to be redefined in a subclass.
The algorithm can be used multiple times after construction.
It is run by a call to the execute(.) method, which takes an
InspectableTree as its parameter. It produces no output except
any output you cause it to produce in the redefined methods
mentioned above.
Field Summary | |
---|---|
protected InspectableTree |
tree_
The tree on which the algorithm executes. |
Constructor Summary | |
---|---|
EulerTour()
The constructor for the algorithm. |
Method Summary | |
---|---|
void |
execute(InspectableTree tree)
This method should be called after construction. |
protected void |
init()
Called in execute(.), before algorithm is executed. |
protected void |
visitBetweenChildren(Position pos)
Called during execution when a node is visited between visits to its children. |
protected void |
visitExternal(Position pos)
Called during execution when an external node is visited during the Euler tour. |
protected void |
visitFirstTime(Position pos)
Called during execution when a node is first visited in the Euler tour. |
protected void |
visitLastTime(Position pos)
Called during execution when a node is visted for the last time in the Euler tour. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected InspectableTree tree_
Constructor Detail |
---|
public EulerTour()
Method Detail |
---|
public void execute(InspectableTree tree) throws InvalidContainerException
tree
- the InspectableTree to tour
InvalidContainerException
- if the Tree is nullprotected void init()
protected void visitFirstTime(Position pos)
protected void visitBetweenChildren(Position pos)
protected void visitLastTime(Position pos)
protected void visitExternal(Position pos)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |