Please send questions to
st10@humboldt.edu .
//---------------------------------------------------------------------
// File: stack.h
// Name: Sharon M. Tuttle
// last modified: 1-27-05
//
// Template class name: stack
//
// Description: a collection of items such that entries can be
// inserted and removed at only one end (called the top)
//
//---------------------------------------------------------------------
#ifndef STACK_H
#define STACK_H
#include <cstdlib> // provides NULL
using namespace std;
template <typename Item>
class stack
{
public:
/****************************************************/
/* TYPEDEFS and MEMBER CONSTANTS */
/****************************************************/
// initial capacity and amount to increase that capacity
// whenever needed are constants in this particular
// implementation
static const int DEFAULT_CAPACITY = 30;
static const int INCR_AMT = 10;
/*****************************************************/
/* CONSTRUCTOR and DESTRUCTOR */
/*****************************************************/
// postcondition: creates an empty stack instance
//
stack();
// copy constructor (because am using a pointer to
// point to an array, so that array can be replaced with
// a larger one as needed.
stack(const stack<Item>& source);
// destructor (because am using a pointer to point to
// an array, so that array can be replaced with a
// larger one as needed.
//
~stack();
/*************************************************************/
/* ACCESSORS and other constant member functions (observers) */
/*************************************************************/
// postcondition: returns true if stack is empty, and
// returns false otherwise
//
bool is_empty( ) const;
// precondition: is_empty() == false
//
// postcondition: returns the value of the top item of the
// stack, BUT the stack is unchanged.
//
Item get_top( ) const;
/*****************************************************/
/* MODIFIERS and other modifying member functions */
/*****************************************************/
// postcondition: a new copy of entry has been pushed
// onto the (top of the) stack
//
void push(const Item& entry);
// precondition: is_empty() == false
//
// postcondition: the top item of the stack has been
// removed, and a reference to it is returned
//
Item& pop( );
private:
/*****************************************************/
/* DATA FIELDS */
/*****************************************************/
Item *data; // a pointer, eventually to point to
// an array
int used; // how much of array contains stack
// elements
int capacity; // NOT a constant, because how much
// stack "can" hold CAN change
};
#include "stack.template" // Include the template implementation
#endif