1: /**
2: A class of stacks whose entries are stored in an array.
3: @author Frank M. Carrano and Timothy M. Henry
4: @version 5.0
5: */
6: public final class ArrayStack<T> implements StackInterface<T>
7: {
8: private T[] stack; // Array of stack entries
9: private int topIndex; // Index of top entry
10: private boolean integrityOK = false;
11: private static final int DEFAULT_CAPACITY = 50;
12: private static final int MAX_CAPACITY = 10000;
13:
14: public ArrayStack()
15: {
16: this(DEFAULT_CAPACITY);
17: } // end default constructor
18:
19: public ArrayStack(int initialCapacity)
20: {
21: integrityOK = false;
22: checkCapacity(initialCapacity);
23:
24: // The cast is safe because the new array contains null entries
25: @SuppressWarnings("unchecked")
26: T[] tempStack = (T[])new Object[initialCapacity];
27: stack = tempStack;
28: topIndex = -1;
29: integrityOK = true;
30: } // end constructor
31:
32: // < Implementations of the stack operations go here. >
33: // < Implementations of the private methods go here; checkCapacity and checkIntegrity
34: // are analogous to those in Chapter 2. >
35: // . . .
36: } // end ArrayStack