// This queue will contain Customer items
class Customer
private:
long arrive:
int processtime:
public:
Customer () { arrive = processtime - 0: )
void set (long when):
long when()const ( return arrive: }
int ptime()const ( return processtime: }
// arrival time for customer
// processing time for customer
1:
typedef Customer Item:
class Queue
private:
// class scope definitions
// Node is a nested structure definition local to this class
struct Node ( Item item: struct Node * next; l:
enum (Q_SIZE = 10]:
// private class members
Node * front:
Node * rear:
int items:
const int qsize:
// preemptive definitions to prevent public copying
Queue (const Queue & q): qsize (0) { }
Queue & operator= (const Queue & q) { return *this: }
public:
Queue (int qs = Q_SIZE): // create queue with a qs limit
-Queue ():
bool isempty()const:
bool isfull()const:
int queuecount {)const:
bool enqueue (const Item Gitem);
bool dequeue (Item Gitem);
#endif
程序清单 12.11 queue.cpp
// queue.cpp -- Queue and Customer methods
#include "queue.h"
#include <cstdlib>
// Queue methods
Queue: : Queue (int qs): qsize (qs)
front = rear = NULL:
items = 0:
// pointer to front of Oueue
// pointer to rear of Queue
// current number of items in Queue
// maximum number of items in Queue
// add item to end
// remove item from front
// (or stdlib.h) for rand()
-
-
Queue: :~ Queue ()
Node * temp:
while ifront != NULL)
temp = front:
front = front->next:
// while queue is not yet empty
// save address of front item
// reset pointer to next item