#include #include using namespace std; #define QUEUE_UNDERFLOW 1; // defining an exception for empty queue; class Queue { private: int capacity; int front; int rear; int *ptr; public: Queue(); Queue(int); Queue(Queue&); Queue& operator=(Queue &); void insertAtRear(int); bool isOverflow(); bool isUnderflow(); int viewRearElement(); int viewFrontElement(); void deleteFront(); int countElement(); ~Queue(); }; Queue::Queue() { capacity = 0; front = rear = -1; ptr = NULL; } Queue::Queue(int cap) // constructor { capacity = cap; front = rear = -1; // initially queue is empty. ptr = new int[cap]; } Queue::Queue(Queue& q) // copy constructor { capacity = q.capacity; front = q.front; rear = q.rear; ptr = new int[capacity]; for(int i = 0; i deleting the memory of pointer for( if it containes any other location) capacity = q.capacity; front = q.front; rear = q.rear; ptr = new int[capacity]; for(int i = 0; i front) // if rear is greater than front return (rear-front+1); else return capacity-front+rear+1; // if any case other than all these } Queue::~Queue() { if(ptr != NULL) delete [] ptr; // not necessary to check the NULL Condition because of parametrised constructor. }