Example #1
0
 /// Removes the last entry from the Stack
 /// If the stack is empty pop will return a default value
 /// <returns>deleted stack entry</returns>
 public T Pop()
 {
     if (_currentElement != null)
     {
         T temp = _currentElement.ValueOfElement;
         _currentElement = _currentElement.Successor;
         return(temp);
     }
     else
     {
         throw new NullReferenceException(); //throw an exception because stack is entry
     }
 }
Example #2
0
        private StapelElement <T> _currentElement; //stores the latest entry of the stack

        /// Adds new Elements to the stack
        /// <param name="item">item which should be added to the stack</param>
        public void Push(T item)
        {
            if (_currentElement == null)
            {
                _currentElement = new StapelElement <T>()
                {
                    ValueOfElement = item, Successor = null
                };
            }
            else
            {
                StapelElement <T> temp = new StapelElement <T>()
                {
                    ValueOfElement = item, Successor = _currentElement
                };
                _currentElement = temp;
            }
        }