/**
 * A Stack (of Object objects)
 *
 * This implementation uses linked memory
 *
 * @version 1.0
 * @author  Prof. David Bernstein, James Madison University
 */
    public class Stack
   {
      private Node top;
   
   
    /**
     * Construct a new (empty) Stack
     */
       public Stack()
      {
         top = null;
      }
   
   
   
    /**
     * Pop an Object off of the top of this Stack
     *
     * @return  The Object on the top of this Stack
     */
       public Object pop()
      {
         Object  value;
      
      
         if (top != null) 
         {
            value = top.value;
            top = top.next;
         } 
         else
         {
            value = null;
         }
      
         return value;
      }
   
   
    /**
     * Push an Object onto the top of this Stack
     *
     * @param first   The Object to push
     */
       public void push(Object first)
      {
         Node temp;
      
         temp = new Node();
      
         temp.value = first;
         temp.next = top;
      
         top = temp;
      }
   
       private class Node
      {
         Object value;
         Node next;
      }
   
   }
