public class ArrayStack
1: /**
2: A class of stacks whose entries are stored in an array.
3: @author Frank M. Carrano and Timothy M. Henry
4: @version 4.0
5: */
6: public 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 initialized = 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: checkCapacity(initialCapacity);
22:
23: // The cast is safe because the new array contains null entries
24: @SuppressWarnings("unchecked")
25: T[] tempStack = (T[])new Object[initialCapacity];
26: stack = tempStack;
27: topIndex = -1;
28: initialized = true;
29: } // end constructor
30:
31: // < Implementations of the stack operations go here. >
32: // < Implementations of the private methods go here; checkCapacity and
33: // checkInitialization are analogous to those in Chapter 2. >
34: // . . .
35: } // end ArrayStack