示例#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
     }
 }
示例#2
0
 public T Pop()
 {
     if (curEle != null)
     {
         T temp = curEle.ValueOfElement;
         curEle = curEle.Successor;
         return(temp);
     }
     else
     {
         throw new NullReferenceException();
     }
 }
示例#3
0
 public T Pop()
 {
     if (presentElement == null)
     {
         throw new NullReferenceException();
     }
     else
     {
         T temp = presentElement.Value;
         presentElement = presentElement.Predecessor;
         return(temp);
     }
 }
示例#4
0
 public void Push(T element)
 {
     if (presentElement == null)
     {
         presentElement = new StackElement <T>()
         {
             Value = element, Predecessor = null
         };
     }
     else
     {
         StackElement <T> temp = new StackElement <T> {
             Value = element, Predecessor = presentElement
         };
         presentElement = temp;
     }
 }
示例#5
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) //if null I need to create a new StackElement first, no successor exists
            {
                currentElement = new StackElement <T>()
                {
                    ValueOfElement = item, Successor = null
                };
            }
            else
            {
                StackElement <T> temp = new StackElement <T>()
                {
                    ValueOfElement = item, Successor = currentElement
                };                                                                                                  //actual current element will become successor, temp will be the new current element
                currentElement = temp;
            }
        }
示例#6
0
 public void Push(T item)
 {
     if (curEle == null)
     {
         curEle = new StackElement <T>()
         {
             ValueOfElement = item, Successor = null
         };
     }
     else
     {
         StackElement <T> temp = new StackElement <T>()
         {
             ValueOfElement = item, Successor = curEle
         };
         curEle = temp;
     }
 }