Algorithm Insertion and Deletion in Queue in Data Structure

Queue:

A queue is a linear data structure in which deletion can take place only at one end which is called the Front, and insertions can take place only at the other end is called the Rear.

Algorithm for insertion into the queue:

Algorithm fnQinsertion (arrQueue[], Data)
{
if(fnQFull()==TRUE) // Check for queue full condition
Queue is Full;
else
{
arrQueue[rear]=Data; // Insert the item Data onto queue.
rear=rear+1;
}
} // End of Algorithm

Algorithm for deletion from the linear queue:

Algorithm fnQdeletion (arrQueue[])
{
if(fnQEmpty()==TRUE) // Check for queue empty condition
Queue is empty;
else
{
Data=arrQueue[front]; // item deleted
front=front+1;
return Data;
}
}