예제 #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;
     }
 }