Page 94 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 94
Unit 4: Queues
if(front == NULL) Notes
{
front = x;
x->next = NULL;
rear = x;
}
/* x is the first node being added to the priority queue*/
elseif(front->priority < p)
{
x->next = front;
front = x;
}
/* x has the highest priority hence should be at the front*/
elseif(rear->priority > p)
{
x->next = NULL;
rear->next = x;
rear = x;
}
/* x has the least priority hence should be at the rear*/
else
{
/* x has to be inserted in between according to its priority*/
f = front;
pr = f->pri; r = NULL;
while(pr > p) /* Advance through the queue till the proper position is
reached */
{
f = f->next; r = f; pr = f->priority;
}
/* f now points to the node before which x has to be inserted and r points
to the node which should be before x*/
r->next = x; x->next = f;
}
}
Task Write an implementation of the Extended_queue method full. In light of the
simplicity of this method in the linked implementation, why is it still important to include
it in the linked class Extended_queue?
LOVELY PROFESSIONAL UNIVERSITY 89