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