예제 #1
0
        public LightStack(T element)
        {
            if ((dynamic)element is null)
            {
                throw new ArgumentNullException(String.Format("{0} is null", nameof(element)));
            }

            current = new StackElement <T>(element);
        }
예제 #2
0
        public void Push(T element)
        {
            if (current == null)
            {
                current = new StackElement <T>(element);
            }
            else
            {
                current = new StackElement <T>(element, current);
            }

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, element));
            Count++;
        }
예제 #3
0
        public T Pop()
        {
            if (current is null)
            {
                throw new InvalidOperationException("Stack is empty");
            }

            T temp = current.Element;

            current = current.PreviousElement;
            Count--;

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, temp));
            return(temp);
        }
예제 #4
0
        public IEnumerator <T> GetEnumerator()
        {
            StackElement <T> temp = current;

            while (true)
            {
                if (temp is null)
                {
                    yield break;
                }

                yield return(temp.Element);

                temp = temp.PreviousElement;
            }
        }
예제 #5
0
 public StackElement(T element, StackElement <T> previousElement) : this(element)
 {
     PreviousElement = previousElement;
 }
예제 #6
0
 public void Reverse()
 {
     current = GetReversedVersion().current;
 }