Example #1
0
 public static IEnumerable <T> DepthFirstEnumerator <T>(this IValuedTree <T> tree)
 {
     foreach (var child in tree.GetChildren())
     {
         foreach (var value in child.DepthFirstEnumerator())
         {
             yield return(value);
         }
     }
     if (tree.HasValue)
     {
         yield return(tree.Value);
     }
 }
Example #2
0
        public static IEnumerable <T> NthEnumerator <T>(this IValuedTree <T> tree, int position)
        {
            foreach (var child in tree.GetChildren())
            {
                if (position == 0 && tree.HasValue)
                {
                    yield return(tree.Value);
                }
                foreach (var value in child.BreadthFirstEnumerator())
                {
                    yield return(value);
                }
                position--;
            }

            if (position >= 0 && tree.HasValue)
            {
                yield return(tree.Value);
            }
        }