/// <summary> /// Performs a depth first traversal on this tree with the specified visitor. /// </summary> /// <param name="orderedVisitor">The ordered visitor.</param> /// <exception cref="ArgumentNullException"><paramref name="orderedVisitor"/> is a null reference (<c>Nothing</c> in Visual Basic).</exception> public virtual void DepthFirstTraversal(OrderedVisitor <T> orderedVisitor) { Guard.ArgumentNotNull(orderedVisitor, "orderedVisitor"); if (orderedVisitor.HasCompleted) { return; } // Preorder visit orderedVisitor.VisitPreOrder(Data); if (leftSubtree != null) { leftSubtree.DepthFirstTraversal(orderedVisitor); } // In-order visit orderedVisitor.VisitInOrder(data); if (rightSubtree != null) { rightSubtree.DepthFirstTraversal(orderedVisitor); } // PostOrder visit orderedVisitor.VisitPostOrder(Data); }
public IEnumerator <T> GetOrderedEnumerator() { if (tree != null) { var trackingVisitor = new TrackingVisitor <T>(); var inOrderVisitor = new InOrderVisitor <T>(trackingVisitor); tree.DepthFirstTraversal(inOrderVisitor); var trackingList = trackingVisitor.TrackingList; for (var i = 0; i < trackingList.Count; i++) { yield return(trackingList[i]); } } }