Code Fragment: DequeStack



template <typename Object>
class DequeStack {
private:                                        // member data
  LinkedDeque<Object> D;			// the deque
public:
  DequeStack() : D() { }			// default constructor
  int size() const { return D.size(); }		// number of elements in stack
  bool isEmpty() const { return D.isEmpty(); }	// is the stack empty?
						// return the top of the stack
  const Object& top() const throw(StackEmptyException) {
    try {
      return D.first();
    } catch (const DequeEmptyException& e) {
      throw StackEmptyException("Top of empty stack");
    }
  }
  void push(const Object& elem)			// push onto stack
    { D.insertFirst(elem); }
  Object pop() throw(StackEmptyException) {	// pop the stack
    try {
      Object result = D.first();
      D.removeFirst();
      return result;
    } catch (const DequeEmptyException& e) {
      throw StackEmptyException("Pop of empty stack");
    }
  }  
};