public class GenericStack { private T[] items; private int top; // Index of the next place to put a T object public GenericStack(int size) { items = (T[]) new Object[size]; top = 0; } public boolean isEmpty() { return (top == 0); } public boolean isFull() { return (top == items.length); } public boolean push(T item) { if(isFull()) { // No place to put the object return false; } else { // Add the object to the next open slot items[top] = item; top += 1; return true; } } public T pop() { if(isEmpty()) { // Nothing to pop return null; } else { // Return the item at the top of the stack top -= 1; return items[top]; } } public void displayState() { System.out.println("####"); for(int i = top - 1; i >= 0; --i) { System.out.println(items[i]); } } }