public LightStack(T element) { if ((dynamic)element is null) { throw new ArgumentNullException(String.Format("{0} is null", nameof(element))); } current = new StackElement <T>(element); }
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++; }
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); }
public IEnumerator <T> GetEnumerator() { StackElement <T> temp = current; while (true) { if (temp is null) { yield break; } yield return(temp.Element); temp = temp.PreviousElement; } }
public StackElement(T element, StackElement <T> previousElement) : this(element) { PreviousElement = previousElement; }
public void Reverse() { current = GetReversedVersion().current; }