#include <iostream>
#include <deque>
#include <stack>
using namespace std;

#ifndef BOUNDEDSTACK
#define BOUNDEDSTACK

template <class StackElement>
class BoundedStack : public stack<StackElement>
{
/***** Function Members *****/
public:
/* --- Constructor ---
 *
 * Precondition:  A BoundedStack has been declared.
 * Receive:       a limit on the size of the bounded stack
 * Postcondition: The BoundedStack has been constructed 
 *                 as an empty stack and with its myLimit
 *                 data member initialized to limit (default 0).
 **************************************************************/

BoundedStack(int limit = 0);

/* --- Add a value to the stack if there is room---
 *
 * Receive:   The BoundedStack containing this function 
 *              (implicitly)
 *            A value to be added to a BoundedStack 
 * Pass back: The BoundedStack (implicitly), with value 
 *              added at its top, provided there is room
 * Output:    Overflow message if no room for value
 **************************************************************/

void push(const StackElement & value);

/***** Data Members *****/
protected:
  int myLimit;
};  // end of class template declaration

//--- Definition of Constructor ---
template <class StackElement>
inline BoundedStack<StackElement>::
BoundedStack(int limit)
: stack<StackElement>()
{ myLimit = limit; }

//--- Definition of push() ---
template <class StackElement>
inline void BoundedStack<StackElement>::
push(const StackElement & value)
{
  if (size() < myLimit)
    stack<StackElement>::push(value);
  else
    cerr << "*** Bounded stack overflow ***\n";
}

#endif
