Think of a tree as a collection of nodes.
There are many kinds of collections, hashtables linked lists dynamic arrays, heaps, stacks...
In a collection you might sometimes want to iterate through all the nodes, and thats what the iterator is for. The order does not matter.
But how does the Iterator implement this in a Tree ADT?
Example for a height calculating method ( in a Tree ):
public static int height2(Tree T, Position v){
if(T.isExternal(v))
return 0;
else{
int h = 0;
Iterator children = T.children(v); //What does the Iterator do?
while (children.hasNext())
h = Math.max(h, height2(T, (Position) children.next()));
return 1 + h;
}
}
There are many kinds of trees.
A tree node might have more descendants than direct children, so an iterator for the direct children of a node is not the same as an iterator for all nodes in a tree. Direct children excludes the parent, grandchildren, and grandchildrens descendants.