Queue algorithm

Algorithm for Queue enqueue and dequeue operation :-
What is the queue? 
A queue is a linear data structure, there are two end one is front end and second is rear end. 
These are memory represent by array or linked list.
  • Front ( delete an element) 
  • Rear ( insert an element) 
// algorithm insertqueue( queue, N, front, rear, item) 
If  front=1 and rear=N, then(queue is full) " write overflow & return.
If front=null (queue is empty)
         Set front=1 and rear=1
Else
         Rear=rear+1
Set queue[rear] =item
Exit.

//Algorithm deletequeue (queue, N, front, rear, item) 

If front=null (queue is empty), then write" umderflw and return. 
Set item=queue[front] 
If front=rear( gueue is one element) 
Set front=null and rear =null
Else
      front=front+1
Exit.

Comments