import java.util.*;

/**
 * The MyStack class is a LIFO list.  Elements are added to the begining of the stack
 * and removed from the beginning of the stack.
 */
public class MyStack
{
    private Vector list;
    
    /** 
     * Constructor
     */
    public MyStack()
    {
	list = new Vector();
    }
    
    /**
     * Add an element to the stak.
     *
     * @param o the object to add to the BEGINNING of the list.
     */
    public void push(Object o)
    {
	if (o != null)
	    list.insertElementAt(o, 0);
    }
    
    /**
     * Remove and element from the beginning of the list.
     *
     * @return the first element in the list, or null if there are no more elements.
     */
    public Object pop()
    {
	// Make sure we have elements to return.
	if (list.size() == 0)
	    return null;
	return list.remove(0);
    }
    
    /**
     * This method is ONLY for this demo.  It's usually a BAD THING to provide
     * a handle to your private contents like this.  However, for this example, we
     * needed to be able to list the contents easily.
     * <p>
     * The REAL way to do this would have been to return an Enumeration of the Vector.
     *
     * @return the contents as Vector.
     */ 
    public Vector getList()
    {
	return list;
	// We *should* return list.elements(), an Enumeration.  But we're lazy!
    }

}
