Beispiel #1
0
 /// <summary>
 /// Removes the last entry from the Stack
 /// If the stack is empty pop will return a default value
 /// </summary>
 /// <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 becasue stack is entry
     }
 }
Beispiel #2
0
        private StackElement <T> currentElement; //stores the latest entry of the stack

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