コード例 #1
0
        /// <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");
            }

            VisitableStack <RedBlackTreeNode <TKey, TValue> > 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);
                    }
                }
            }
        }
コード例 #2
0
        /// <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)
            {
                VisitableStack <BinaryTree <Association <TKey, TValue> > > stack = new VisitableStack <BinaryTree <Association <TKey, TValue> > >();

                stack.Push(tree);

                while (!stack.IsEmpty)
                {
                    BinaryTree <Association <TKey, TValue> > t = stack.Pop();

                    yield return(t.Data.ToKeyValuePair());

                    if (t.Left != null)
                    {
                        stack.Push(t.Left);
                    }

                    if (t.Right != null)
                    {
                        stack.Push(t.Right);
                    }
                }
            }
        }
コード例 #3
0
ファイル: GeneralTree.cs プロジェクト: jungs1330/ZProjects
        /// <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()
        {
            VisitableStack <GeneralTree <T> > stack = new VisitableStack <GeneralTree <T> >();

            stack.Push(this);

            while (!stack.IsEmpty)
            {
                GeneralTree <T> tree = stack.Pop();

                if (tree != null)
                {
                    yield return(tree.Data);

                    for (int i = 0; i < tree.Degree; i++)
                    {
                        stack.Push(tree.GetChild(i));
                    }
                }
            }
        }
コード例 #4
0
ファイル: BinaryTree.cs プロジェクト: jungs1330/ZProjects
        /// <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()
        {
            VisitableStack <BinaryTree <T> > stack = new VisitableStack <BinaryTree <T> >();

            stack.Push(this);

            while (!stack.IsEmpty)
            {
                BinaryTree <T> tree = stack.Pop();

                yield return(tree.Data);

                if (tree.leftSubtree != null)
                {
                    stack.Push(tree.leftSubtree);
                }

                if (tree.rightSubtree != null)
                {
                    stack.Push(tree.rightSubtree);
                }
            }
        }
コード例 #5
0
        /// <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()
        {
            VisitableStack <RedBlackTreeNode <TKey, TValue> > 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);
                }
            }
        }