/**
 * A Stack (of Object objects)
 *
 * This implementation uses contiguous memory
 *
 * @version 1.0
 * @author  Prof. David Bernstein, James Madison University
 */
public class Stack
{
    private int         top;
    private Object[]    contents;

    public static final int CAPACITY = 100;

    /**
     * Construct a new (empty) Stack
     */
    public Stack()
    {
	top = -1;
	contents = new Object[CAPACITY];
    }



    /**
     * 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 != -1) 
        {
	    value = contents[top];
	    top   = top - 1;
	} 
	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)
    {
	if (top < CAPACITY-1)
	{
	    top = top + 1;

	    contents[top] = first;
	}
    }
}
