/// <summary> /// Accepts the specified visitor. /// </summary> /// <param name="visitor">The visitor.</param> public void Accept(IVisitor <KeyValuePair <TKey, TValue> > visitor) { if (visitor == null) { throw new ArgumentNullException("visitor"); } var stack = new VisitableStack <RedBlackTreeNode <TKey, TValue> >(); stack.Push(root); while (!stack.IsEmpty) { if (!visitor.HasCompleted) { RedBlackTreeNode <TKey, TValue> node = stack.Pop(); visitor.Visit(new KeyValuePair <TKey, TValue>(node.Key, node.Value)); if (node.Left != null) { stack.Push(node.Left); } if (node.Right != null) { stack.Push(node.Right); } } } }
/// <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 <T> GetEnumerator() { var stack = new VisitableStack <GeneralTree <T> >(); stack.Push(this); while (!stack.IsEmpty) { var tree = stack.Pop(); if (tree != null) { yield return(tree.Data); for (var i = 0; i < tree.Degree; i++) { stack.Push(tree.GetChild(i)); } } } }
/// <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> > GetEnumerator() { var stack = new VisitableStack <RedBlackTreeNode <TKey, TValue> >(); stack.Push(root); while (!stack.IsEmpty) { RedBlackTreeNode <TKey, TValue> node = stack.Pop(); yield return(new KeyValuePair <TKey, TValue>(node.Key, node.Value)); if (node.Left != null) { stack.Push(node.Left); } if (node.Right != null) { stack.Push(node.Right); } } }
/// <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 <T> GetEnumerator() { var stack = new VisitableStack <BinaryTree <T> >(); stack.Push(this); while (!stack.IsEmpty) { var tree = stack.Pop(); yield return(tree.Data); if (tree.Left != null) { stack.Push(tree.Left); } if (tree.Right != null) { stack.Push(tree.Right); } } }
/// <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> > GetEnumerator() { if (_tree != null) { var stack = new VisitableStack <BinaryTree <Association <TKey, TValue> > >(); stack.Push(_tree); while (!stack.IsEmpty) { var t = stack.Pop(); yield return(t.Data.ToKeyValuePair()); if (t.Left != null) { stack.Push(t.Left); } if (t.Right != null) { stack.Push(t.Right); } } } }