public int Pop() { if (!IsEmpty()) { size--; StackElement temp = head; head = temp.next; return(temp.value); } Console.WriteLine("Error: stack is Empty"); return(-1); }
public void Push(int value) { var newElement = new StackElement(value); if (IsEmpty()) { head = newElement; size++; return; } newElement.next = head; head = newElement; size++; }
/// <summary> /// Pop an integer from the top of the stack /// </summary> /// <returns>The value of the poped integer</returns> public int Pop() { if (this.size == 0) { throw new InvalidOperationException("Попытка удалить элемент из пустого стэка."); } int value = this.head.Value(); this.head = this.head.Next(); --this.size; return(value); }
public StackElement(int value, StackElement next) { this.value = value; this.next = next; }
/// <summary> /// Push an integer to the top of the stack /// </summary> /// <param name="value">The value of the integer added to the stack</param> public void Push(int value) { this.head = new StackElement(value, this.head); ++this.size; }
public MyStack(object value) { Root = new StackElement(value); Count++; }