Linear queues using arrays have certain drawbacks listed as follows:
1. The linear queue is of a fixed size.
2. Poor utilization of memory. (Ex: using only 20 but declaring max size 100)
3. Array implementation of linear queues leads to the Queue_Full state even though the queue is not actually full.
The functions to add and delete elements are:
void Cqueue :: Add(int Element)
{
if(!Full())
Rear = (Rear + 1) % Max;
Queue[Rear] = Element;
Size++;
}
int Cqueue :: Delete()
{
if(!Empty())
Front = (Front + 1) % Max;
Size--;
return(Queue[Front]);
}
Advantages of Using Circular Queues
1. Data shifting is avoided as the front and rear are modified by using the mod() function. The mod() operation wraps the queue back to its beginning.
2. If the number of elements to be stored in the queue is fixed, the circular queue is advantageous.
3. Many practical applications such as printer queue, priority queue, and simulations use the circular queue.
0 comments:
Post a Comment