Page 180 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 180
Unit 10: Queues
dq[front] = y; Notes
if (front == -1) front = 0;
}
}
/**************** Delete from the front ***************/
delete_front()
{
if front == -1
printf(“Queue empty”);
else
return dq[front];
if (front = = rear)
front = rear = -1
else
front = front + 1;
}
/**************** Add at the rear ***************/
add_rear(int y)
if (front == QUEUE_LENGTH -1)
{
printf(“Element can not be added at the rear”)
return;
else
{
rear = rear + 1;
dq[rear] = y;
if (rear = = – 1)
rear = 0;
}
}
/**************** Delete at the rear ***************/
delete_rear()
{
if rear == - 1
printf(“deletion is not possible from rear”);
else
{
if (front = = rear)
front = rear = - 1
else
{ rear = rear – 1;
LOVELY PROFESSIONAL UNIVERSITY 173