org.jikesrvm.compilers.opt.util
Class TreeBottomUpEnumerator

java.lang.Object
  extended by org.jikesrvm.compilers.opt.util.TreeBottomUpEnumerator
All Implemented Interfaces:
Enumeration<TreeNode>

final class TreeBottomUpEnumerator
extends Object
implements Enumeration<TreeNode>

This class provides enumeration of a tree in bottom-up order It guarantees that all children of a node will be visited before the parent. This is not necessarily the same as a bottom-up level walk.


Field Summary
private  ListIterator<TreeNode> iterator
          an iterator of the above list
private  ArrayList<TreeNode> list
          List of nodes in postorder
 
Constructor Summary
TreeBottomUpEnumerator(TreeNode root)
          constructor: it creates the list of nodes
 
Method Summary
private  void DFS(TreeNode node)
          A postorder depth first traversal, adding nodes to the list
 boolean hasMoreElements()
          any elements left?
 TreeNode nextElement()
          returns the next element in the list iterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

list

private final ArrayList<TreeNode> list
List of nodes in postorder


iterator

private final ListIterator<TreeNode> iterator
an iterator of the above list

Constructor Detail

TreeBottomUpEnumerator

TreeBottomUpEnumerator(TreeNode root)
constructor: it creates the list of nodes

Parameters:
root - Root of the tree whose elements are to be visited.
Method Detail

hasMoreElements

public boolean hasMoreElements()
any elements left?

Specified by:
hasMoreElements in interface Enumeration<TreeNode>
Returns:
whether there are any elements left

nextElement

public TreeNode nextElement()
returns the next element in the list iterator

Specified by:
nextElement in interface Enumeration<TreeNode>
Returns:
the next element in the list iterator or null

DFS

private void DFS(TreeNode node)
A postorder depth first traversal, adding nodes to the list

Parameters:
node -