Пример #1
0
 public int Pop()
 {
     if (!IsEmpty())
     {
         size--;
         StackElement temp = head;
         head = temp.next;
         return(temp.value);
     }
     Console.WriteLine("Error: stack is Empty");
     return(-1);
 }
Пример #2
0
        public void Push(int value)
        {
            var newElement = new StackElement(value);

            if (IsEmpty())
            {
                head = newElement;
                size++;
                return;
            }
            newElement.next = head;
            head            = newElement;
            size++;
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
 public StackElement(int value, StackElement next)
 {
     this.value = value;
     this.next  = next;
 }
Пример #5
0
 /// <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;
 }
Пример #6
0
 public MyStack(object value)
 {
     Root = new StackElement(value);
     Count++;
 }