public static IEnumerable <IPathTreeNode <T> > Ancestors <T>(this IPathTreeNode <T> node) { IPathTreeNode <T> nodeVisitor = node.Parent; while (nodeVisitor != null) { yield return(nodeVisitor); nodeVisitor = nodeVisitor.Parent; } }
public static IEnumerable <IPathTreeNode <T> > DescendantsDepthFirst <T>(this IPathTreeNode <T> node) { var nodeStack = new Stack <IPathTreeNode <T> >(node.Children); while (nodeStack.Count > 0) { var popNode = nodeStack.Pop(); yield return(popNode); foreach (var child in popNode.Children) { nodeStack.Push(child); } } }
public static IEnumerable <IPathTreeNode <T> > DescendantsBreadthFirst <T>(this IPathTreeNode <T> node) { var nodeQueue = new Queue <IPathTreeNode <T> >(); nodeQueue.Enqueue(node); while (nodeQueue.Count > 0) { var dequeueNode = nodeQueue.Dequeue(); yield return(dequeueNode); foreach (var child in dequeueNode.Children) { nodeQueue.Enqueue(child); } } }
public PathTree() { Root = new PathTreeBranchNode(); }