Пример #1
0
 public Person Pop()
 {
     if (currentElement != null)
     {
         Person temp = currentElement.ValueOfElement;
         currentElement = currentElement.Successor;
         return(temp);
     }
     else
     {
         throw new NullReferenceException();
     }
 }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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;
            }
        }
Пример #4
0
 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;
     }
 }