Iterator Pattern Code Review

Use the Iterator Pattern

Code Review

Code Walkthrough

The Program class creates the family tree structure and stores this in a variant variable, which will at runtime be converted to a Tree type.

class Program { static void Main(string[] args) { var family = new Tree( new Node(new Person("Tom", 1950), new Node(new Person("Peter", 1976), new Node(new Person("Sarah", 2000), null, new Node(new Person("James", 2002), null, null)), new Node(new Person("Robert", 1978), null, new Node(new Person("Mark", 1982), new Node(new Person("Carrie", 2005), null, null), null))), null) );
Console.WriteLine("Full Family"); foreach (Person p in family.Preorder) { Console.Write("{0} ", p); } Console.WriteLine("\n");
var selection = from p in family where p.Birth > 1980 orderby p.Name select p;
Console.WriteLine("Born after 1980 in alpha order"); foreach (Person p in selection) { Console.Write("{0} ", p); } Console.WriteLine("\n"); Console.Read(); } }

The code transverses through the Tree structure and displays all the nodes. Finally, using LINQ syntax the family tree is filtered by birth year and results displayed.