public Person Pop() { if (currentElement != null) { Person temp = currentElement.ValueOfElement; currentElement = currentElement.Successor; return(temp); } else { throw new NullReferenceException(); } }
/// <summary> /// Pops a value from the stack (read and delete) /// </summary> /// <returns>the value of the last element</returns> public T Pop() { if (_currentElement == null) { throw new NullReferenceException("No elements at the stack!"); } var value = _currentElement.Value; _currentElement = _currentElement.Previous; return(value); }
/// <summary> /// pushes a value to the stack /// </summary> /// <param name="value">the value</param> public void Push(T value) { var newElement = new StackElement <T>(value); if (_currentElement == null) { _currentElement = newElement; } else { newElement.Previous = _currentElement; _currentElement = newElement; } }
public void Push(Person item) { if (currentElement == null) { currentElement = new StackElement() { ValueOfElement = item, Successor = null }; } else { StackElement temp = new StackElement() { ValueOfElement = item, Successor = currentElement }; currentElement = temp; } }