Please send questions to
st10@humboldt.edu .
//---------------------------------------------------------------------
// File: queue.h
// Name: Sharon M. Tuttle
// last modified: 2-1-05
//
// Template class name: queue
//
// Description: a collection of items such that entries can be
// inserted at one end (called the rear) and removed at the
// other end (called the front).
//
//---------------------------------------------------------------------
#ifndef QUEUE_H
#define QUEUE_H
#include <cstdlib> // provides NULL
using namespace std;
template <typename Item>
class queue
{
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;
/*****************************************************/
/* CONSTRUCTORS and DESTRUCTOR */
/*****************************************************/
// postcondition: creates an empty queue instance
//
queue();
// copy constructor (because am using a pointer to
// point to an array, so that array can be replaced with
// a larger one as needed.
//
queue(const queue<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.
//
~queue();
/*************************************************************/
/* ACCESSORS and other constant member functions (observers) */
/*************************************************************/
// postcondition: returns true if queue is empty, and
// returns false otherwise
//
bool is_empty( ) const;
// precondition: is_empty() == false
//
// postcondition: returns the value of the front item of the
// queue, BUT the queue is unchanged.
//
Item get_front( ) const;
/*****************************************************/
/* MODIFIERS and other modifying member functions */
/*****************************************************/
// postcondition: a new copy of entry has been inserted
// at the rear of the queue
//
void enqueue(const Item& entry);
// precondition: is_empty() == false
//
// postcondition: the front item of the queue has been
// removed, and a reference to it is returned
//
Item& dequeue( );
private:
/*****************************************************/
/* DATA FIELDS */
/*****************************************************/
Item *data; // a pointer, eventually to point to
// an array
int used; // how much of array contains queue
// elements
int capacity; // NOT a constant, because how much
// queue "can" hold CAN change
int first; // index of item at front of queue
int last; // index of item at rear of queue
};
#include "queue.template" // Include the template implementation
#endif