// Arup Guha
// 3/20/01
// Program Description: A simple version of a generic stack class. Each stack
//                      element is simply an object of the Object class.
public class MyStack {

    final static int SIZE = 100; // SIZE of ALL stacks
    Object[] items; // Array that stores stack items
    int top_index; // Index of item at top of the stack

    // Creates an empty stack
    public MyStack() {
	items = new Object[SIZE];
	top_index = -1;
    }

    // Returns the top element of the stack, if it exists.
    public Object Top() {
	if (!Empty())
	    return items[top_index];
	else
	    return null;
    }

    // Pops off the top element of the stack, if it exists.
    public Object Pop() {
	if (!Empty()) {
	    top_index--;
	    return items[top_index+1];
	}
	else
	    return null;
    }

    // Pushes an object onto the stack if it is not full. If it is, the
    // method does nothing and returns false.
    public boolean Push(Object obj) {
	if (!Full()) {
	    top_index++;
	    items[top_index] = obj;
	    return true;
	}
	else
	    return false;
    }

    // Returns true iff the stack is empty.
    public boolean Empty() {
	if (top_index == -1)
	    return true;
	else 
	    return false;
    }

    // Returns true iff the stack is full.
    public boolean Full() {
	if (top_index == SIZE - 1)
	    return true;
	else
	    return false;
    }

    public static void main(String[] args) {

	Integer x = new Integer(2001);
	String y = new String("Madness");
	String z = new String("March");
	String w = new String("April");

	MyStack mine = new MyStack();
	mine.Push(w);
	System.out.println((String)mine.Top());
	mine.Pop();
	mine.Push(x);
	mine.Push(y);
	mine.Push(z);
	System.out.print((String)mine.Pop()+" ");
	System.out.print((String)mine.Pop()+" ");
	System.out.println((Integer)mine.Pop());
    }
	
}

