//Circular Queue #include using namespace std; template class Queue { public: Queue (int m); ~Queue (); void Enqueue (x e); void Dequeue (x& e); int QueueIsFull (); int QueueIsEmpty (); void QueueRetreive (x& e); private: int maxsize; x *p; int rear; int front; int n; }; int main() { Queue q(20); int i; q.Enqueue(1); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(5); q.Enqueue(8); q.Dequeue(i); cout << i << endl; q.Dequeue(i); cout << i << endl; q.Dequeue(i); cout << i << endl; return 0; } template Queue::Queue(int m) { maxsize = m; p = new x[maxsize]; rear = -1; front = -1; n = 0; } template Queue::~Queue() { delete [] p; rear = front = -1; } template int Queue::QueueIsFull() { if ((rear == maxsize - 1) && (front == -1)) return 1; if ((rear == front) && (n == 1)) return 1; return 0; } template int Queue::QueueIsEmpty() { if ((rear == front) && (n == 0)) return 1; return 0; } template void Queue::Enqueue(x e) { if(!QueueIsFull()){ rear = (rear + 1) % maxsize; p[rear] = e; n = 1; } } template void Queue::Dequeue(x& e) { if(!QueueIsEmpty()){ front = (front + 1) % maxsize; e = p[front]; n = 0; } } template void Queue::QueueRetreive(x& e){ if(!QueueIsEmpty()){ int k = front; front = (front + 1) % maxsize; e = p[front]; front = k; } }