// Stackx.java
    // basic stacks -- core from Lafore
    ////////////////////////////////////////////////////////////////

public class StackX
{
    private int maxSize;        // size of stack array
    private Object[] stackArray;
    private int top;            // top of stack
    //--------------------------------------------------------------
    public StackX(int s)         // constructor
    {
	maxSize = s;             // set array size
	stackArray = new Object[maxSize];  // create array
	top = -1;                // no items yet
    }
    //--------------------------------------------------------------
    public void push(Object j)    // put item on top of stack
    {
	stackArray[++top] = j;     // increment top, insert item
    }
    //--------------------------------------------------------------
    public Object pop()           // take item from top of stack
    {
	return stackArray[top--];  // access item, decrement top
    }
    //--------------------------------------------------------------
    public Object peek()          // peek at top of stack
    {
	return stackArray[top];
    }
    //--------------------------------------------------------------
    public boolean isEmpty()    // true if stack is empty
    {
	return (top == -1);
    }
    //--------------------------------------------------------------
    public boolean isFull()     // true if stack is full
    {
	return (top == maxSize-1);
    }

    public void display() {
	for (int j=0; j<=top; j++){
	    System.out.println("Item[" + j + "]: " + stackArray[j]);
	}
    }
    //--------------------------------------------------------------
}  // end class StackX
