Code Fragment: ArrayStack1



template <typename Object>
class ArrayStack {
private:                                // member data
  enum { CAPACITY = 1000 };		// default capacity of stack
  int       capacity;			// actual length of stack array
  Object*   S;				// the stack array
  int       t;				// index of the top of the stack
public:
  					// constructor given max capacity
  ArrayStack(int cap = CAPACITY) {
    capacity  = cap;
    S         = new Object[capacity];
    t         = -1;
  }
  int size() const  			// number of elements in the stack
    { return (t + 1); }
  bool isEmpty() const 			// is the stack empty?
    { return (t < 0); }
  					// return the top of the stack
  Object& top() throw(StackEmptyException) {
    if (isEmpty())
      throw StackEmptyException("Access to empty stack");
    return S[t];
  }
  					// push object onto the stack
  void push(const Object& elem) throw(StackFullException) {
    if (size() == capacity)
      throw StackFullException("Stack overflow");
    S[++t] = elem;
  }
 					// pop the stack
  Object pop() throw(StackEmptyException) {
    if (isEmpty())
      throw StackEmptyException("Access to empty stack");
    return S[t--];
  }
  // ...