Example #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);
        }
Example #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++;
        }
Example #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);
        }
Example #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;
            }
        }
Example #5
0
 public StackElement(T element, StackElement <T> previousElement) : this(element)
 {
     PreviousElement = previousElement;
 }
Example #6
0
 public void Reverse()
 {
     current = GetReversedVersion().current;
 }