/** * Implementation of the Stack interface using a fixed-length array. * An exception is thrown if a push operation is attempted when the size of * the stack is equal to the length of the array. * * @author Natasha Gelfand * @author Roberto Tamassia * @see StackFullException */ public class ArrayStack implements Stack { /** * Default length of the array used to implement the stack. */ public static final int CAPACITY = 1000; /** * Lenght of the array used to implement the stack. */ private int capacity; /** * Array used to implement the stack. */ private Object S[]; /** * Index of the top element of the stack in the array. */ private int top = -1; /** * Initialize the stack to use an array of default length CAPACITY. */ public ArrayStack() { this(CAPACITY); } /** * Initialize the stack to use an array of given length. * * @param cap length of the array. */ public ArrayStack(int cap) { capacity = cap; S = new Object[capacity]; }