示例#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;
     }
 }