private void populatePostOrder(TreeNode<T> currentNode, final LinkedList<TreeNode<T>> stack) { List<TreeNode<T>> children = currentNode.getChildren(); for (TreeNode<T> childNode : children) { populatePostOrder(childNode, stack); } stack.addLast(currentNode); }
public Iterator<TreeNode<T>> getPostOrderIter() { final LinkedList<TreeNode<T>> stack = new LinkedList<TreeNode<T>>(); populatePostOrder(this, stack); return stack.iterator(); }