示例#1
0
        /// <summary>Creates a shallow clone of this data structure.</summary>
        /// <returns>A shallow clone of this data structure.</returns>
        public FirstInLastOutLinked <T> Clone()
        {
            FirstInLastOutLinked <T> clone = new FirstInLastOutLinked <T>();

            if (_count == 0)
            {
                return(clone);
            }
            Node copying  = _top;
            Node cloneTop = new Node(_top.Value, null);
            Node cloning  = cloneTop;

            while (copying != null)
            {
                copying      = copying.Down;
                cloning.Down = new Node(copying.Value, null);
                cloning      = cloning.Down;
            }
            clone._top = cloneTop;
            return(clone);
        }
示例#2
0
        public IEnumerator <T> GetEnumerator()
        {
            IFirstInLastOut <Node> forks = new FirstInLastOutLinked <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;
                }
            }
        }