/// <summary> /// Method, which returns value of deleted element from the stack /// </summary> /// <returns>value of the deleted element</returns> public int Pop() { if (!IsEmpty()) { int result = head.Element; head = head.Next; return result; } else { throw new NullReferenceException("No Elements in the stack"); } }
/// <summary> /// Method, which adds a new element in the stack /// </summary> /// <param name="value">value of the element</param> public void Push(int value) { StackElement tmp = new StackElement(head, value); head = tmp; }
public StackElement(StackElement next, int value) { this.Element = value; this.Next = next; }