// Source: "Software Design ...", John A Robinson, Newnes, 2004, page 211. class queue { // First come the private data items int queue_length; // To allow the caller to set max length itemtype **queue_base; // Points to where queue is in memory int head; int tail; public: queue(int size) { queue_base = new itemtype *[queue_length = size]; head = tail = 0; }; ~queue() { delete [] queue_base; } int enqueue(itemtype *); int dequeue(itemtype **); }; int queue::enqueue(itemtype *value) { if ((tail == head-1)||((tail == queue_length-1)&&(head == 0))) return(-1); // Queue full queue_base[tail++] = value; if (tail == queue_length) // Wrap around to start of array tail = 0; return(0); } int queue::dequeue(itemtype **value) { if (head == tail) return(-1); // Queue empty *value = queue_base[head++]; if (head == queue_length) // Wrap around to start of array head = 0; return(0); }