Пример #1
0
        /// <summary>FOR COMPATIBILITY ONLY. AVOID IF POSSIBLE.</summary>
        public System.Collections.Generic.IEnumerator <T> GetEnumerator()
        {
            IStack <Link <Node, int, bool> > forks = new StackLinked <Link <Node, int, bool> >();

            forks.Push(new Link <Node, int, bool>(this._root, 0, false));
            while (forks.Count > 0)
            {
                Link <Node, int, bool> link = forks.Pop();
                if (link._1 == null)
                {
                    continue;
                }
                else if (!link._3)
                {
                    link._3 = true;
                    forks.Push(link);
                    Node child = link._1.Children[link._2];
                    forks.Push(new Link <Node, int, bool>(child, 0, false));
                }
                else if (link._2 < link._1.ItemCount)
                {
                    yield return(link._1.Items[link._2]);

                    link._2++;
                    link._3 = false;
                    forks.Push(link);
                }
            }
        }
Пример #2
0
        /// <summary>Gets the enumerator for this instance.</summary>
        /// <returns>An enumerator to iterate through the data structure.</returns>
        public IEnumerator <T> GetEnumerator()
        {
            IStack <Node> forks   = new StackLinked <Node>();
            Node          current = _root;

            while (current != null || forks.Count > 0)
            {
                if (current != null)
                {
                    forks.Push(current);
                    current = current.LeftChild;
                }
                else if (forks.Count > 0)
                {
                    current = forks.Pop();
                    yield return(current.Value);

                    current = current.RightChild;
                }
            }
        }