|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gshute.trees.TreeEdge
A TreeEdge is an edge between two nodes in a binary tree, providing operations for navigation and obtaining information about nearby nodes, and providing support for implementing iterators. An edge is directed downward, either from an external node to the root node of a tree, or from a node to one of its children. The root node or the child may be external (null).
For an edge from an external node to the root, the from node of the edge is null, the to node is the root, and the edge type is TreeEdge.ROOT. For an edge from a parent node to a child, the from node of the edge is the parent node, the to node is the child, and the edge type is either TreeEdge.LEFT or TreeEdge.RIGHT.
If the underlying tree is modified, a tree edge retains its type and its from node is unaltered. Its to node may change as a result of the modification. If the modification results in removal of the from node then the edge will be left in an invalid state.
When an edge used to implement an iterator, the next element of the iteration is the to node of the edge. The to node of the edge is non-null until the iteration is complete. The current implementation of tree edges only supports the Iterator interface. A planned modification will add support for the ListIterator interface.
Field Summary | |
protected int |
edgeType
edgeType is the type of this edge. |
protected TreeNode |
from
from is the binary tree node from which this edge originates. |
static int |
LEFT
TreeEdge.LEFT is the type constant for describing an edge from a node to its left child. |
static int |
RIGHT
TreeEdge.RIGHT is the type constant for describing an edge from a node to its right child. |
static int |
ROOT
TreeEdge.ROOT is the type constant for describing the edge from an external node to the root. |
protected Tree |
tree
tree is the binary tree that this edge belongs to. |
Constructor Summary | |
TreeEdge(Tree t)
new TreeEdge(t) returns a new tree edge to the root of t. |
Method Summary | |
void |
advanceInorder()
e.advanceInorder() moves e to the edge position whose to node is the inorder successor of the current to node. |
void |
advancePostorder()
e.advancePostorder() moves e to the edge position whose to node is the postorder successor of the current to node. |
void |
advancePreorder()
e.advancePreorder() moves e to the edge position whose to node is the preorder successor of the current to node. |
TreeEdge |
getCopy()
e.getCopy() returns a copy of e. |
int |
getEdgeType()
e.getEdgeType() returns the edge type of e. |
TreeNode |
getFarNiece()
e.getFarNiece() returns the far child of the sibling of the to node of e. |
TreeNode |
getFrom()
e.getFrom() returns the node that e originates from. |
TreeNode |
getNearNiece()
e.getNearNiece() returns the near child of the sibling of the to node of e. |
TreeNode |
getSibling()
e.getSibling() returns the sibling of the to node of e. |
TreeNode |
getTo()
e.getTo() returns the node that e points to. |
Tree |
getTree()
e.getTree() returns the tree that e belongs to. |
void |
goLeft()
e.goLeft() moves e down and to the left. |
void |
goLeftToLastNonNull()
e.goLeftToLastNonNull() moves e left, stopping at the last non-null in the chain of left edges from its current position. |
void |
goLeftToNull()
e.goLeftToNull() moves e left, stopping at the last edge in the chain of left edges from its current position. |
void |
goRight()
e.goRight() moves e down and to the right. |
void |
goRightToLastNonNull()
e.goRightToLastNonNull() moves e right, stopping at the last non-null in the chain of right edges from its current position. |
void |
goRightToNull()
e.goRightToNull() moves e right, stopping at the last edge in the chain of right edges from its current position. |
void |
goToRoot()
e.goToRoot() moves e to the root edge of its tree. |
void |
goUp()
e.goUp() moves e one step towards the root of its tree. |
void |
goUpToNonLeft()
e.goUpToNonLeft() moves e up to the lowest non-left tree edge at or above e. |
void |
goUpToNonRight()
e.goUpToNonRight() moves e up to the lowest non-right tree edge at or above e. |
void |
startInorder()
e.startInorder() moves e to the edge position whose to node is the first node in a inorder traversal. |
void |
startPostorder()
e.startPostorder() moves e to the edge position whose to node is the first node in a postorder traversal. |
void |
startPreorder()
e.startPreorder() moves e to the edge position whose to node is the first node in a preorder traversal. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int LEFT
public static final int ROOT
public static final int RIGHT
protected Tree tree
protected TreeNode from
protected int edgeType
Constructor Detail |
public TreeEdge(Tree t)
Method Detail |
public Tree getTree()
public TreeEdge getCopy()
public int getEdgeType()
public TreeNode getFrom()
public TreeNode getTo()
public TreeNode getSibling()
Preconditions:
e.getEdgeType() != TreeEdge.ROOT
public TreeNode getNearNiece()
Preconditions:
e.getEdgeType() != TreeEdge.ROOT
e.getSibling() != null
public TreeNode getFarNiece()
Preconditions:
e.getEdgeType() != TreeEdge.ROOT
e.getSibling() != null
public void goToRoot()
public void goUp()
Preconditions: e.getType() != TreeEdge.ROOT
public void goUpToNonLeft()
public void goUpToNonRight()
public void goLeft()
Preconditions:
e.getTo() != null
public void goLeftToNull()
public void goLeftToLastNonNull()
Preconditions:
e.getTo() != null
public void goRight()
Preconditions:
e.getTo() != null
public void goRightToNull()
public void goRightToLastNonNull()
Preconditions:
e.getTo() != null
public void startPreorder()
public void advancePreorder()
Preconditions:
e.getTo() != null
public void startInorder()
public void advanceInorder()
Preconditions:
e.getTo() != null
public void startPostorder()
public void advancePostorder()
Preconditions:
e.getTo() != null
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |