/// <summary> /// Performs a depth first traversal on this tree with the specified visitor. /// </summary> /// <param name="orderedVisitor">The ordered visitor.</param> public virtual void DepthFirstTraversal(OrderedVisitor <T> orderedVisitor) { if (orderedVisitor.HasCompleted) { return; } else { // Preorder visit orderedVisitor.VisitPreOrder(Data); if (leftSubtree != null) { leftSubtree.DepthFirstTraversal(orderedVisitor); } // Inorder visit orderedVisitor.VisitInOrder(data); if (rightSubtree != null) { rightSubtree.DepthFirstTraversal(orderedVisitor); } // PostOrder visit orderedVisitor.VisitPostOrder(Data); } }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetSortedEnumerator() { if (tree != null) { TrackingVisitor <Association <TKey, TValue> > trackingVisitor = new TrackingVisitor <Association <TKey, TValue> >(); InOrderVisitor <Association <TKey, TValue> > inOrderVisitor = new InOrderVisitor <Association <TKey, TValue> >(trackingVisitor); tree.DepthFirstTraversal(inOrderVisitor); List <Association <TKey, TValue> > trackingList = trackingVisitor.TrackingList; for (int i = 0; i < trackingList.Count; i++) { yield return(trackingList[i].ToKeyValuePair()); } } }