template class AQueue { private: T *ring; int capacity, count, head, tail; public: // creates an empty queue of the given size. // quits if the capacity is unreasonable. AQueue (int capacity); // enqueues the item at the end of the queue. // quits if no space for item. void enqueue (T item); // dequeues and returns the item from the front of the queue. // quits if queue is empty. T dequeue (); // returns number of items in queue int size () const; // returns the item from the front of the queue, without changing the queue. //quits if queue is empty. T look () const; }; // creates an empty queue of the given size. // quits if the capacity is unreasonable. template AQueue::AQueue (int capacity) { count = head = tail = 0; if (capacity < 1 ) { // initialize fields and quit capacity = 1; ring = new T[1]; quit("AQueue::AQueue - capacity too small\n"); } ring = new T [capacity]; this -> capacity = capacity; } // enqueues the item at the end of the queue. // quits if no space for item. template void AQueue::enqueue (T item) { if (count == capacity) quit("AQueue::enqueue - queue full\n"); ring[tail] = item; count++; tail = (tail + 1) % capacity; } // dequeues and returns the item from the front of the queue. // quits if queue is empty. template T AQueue::dequeue () { T result; if (count == 0) quit("AQueue::dequeue - queue empty\n"); result = ring[head]; count--; head = (head + 1) % capacity; return result; } // returns number of items in queue template int AQueue::size () const { return count; } // returns the item from the front of the queue, without changing the queue. // quits if queue is empty. template T AQueue::look () const { if (count == 0) quit("AQueue::look - queue empty\n"); return ring[head]; }