How would you implement Iterator Pattern for traversing Binary Tree (in any order of your choice)?

So, the following would give an example of using such iterator:

Tree tree = new BinaryTree();
// ...
IEnumerator e = tree.GetEnumerator();
while (e.MoveNext())
{
Object obj = e.Current;
Console.WriteLine(obj);
}

Solution

Sample solution, and detailed explanation can be found here:

Tree Enumerators


Company where asked this question: Amazon (Seattle)






Answers and Comments