ALGORITHM : ENQUE(VALUE,QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data and VALUE is the item to be inserted.This algorithm will insert data into QUEUE. 

1.If REAR=N-1 then : print overflow and return.
2. Set REAR=REAR+1.
3.Set QUEUE[REAR]=VALUE.
4.If FRONT=-1 then :Set FRONT=FRONT+1.
5.Exit


ALGORITHM : DEQUE(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will delete a data from QUEUE. 

1.If FRONT=-1 then : print underflow and return.
2.print QUEUE[FRONT].
3.If FRONT=REAR then :Set FRONT=REAR=-1.
    Else :Set FRONT=FRONT+1.
4.Exit.

ALGORITHM : TRAVERSAL(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will display all the data from QUEUE.

1.If FRONT=-1 then : print queue is empty and return.
2.Set I=FRONT.
3.If I<=REAR then :print QUEUE[I].
4.Set I=I+1.
5.Goto 3.
[End Of Loop.]
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.

Algorithms for array traversal,insertion and deletion are shown below separately.

ALGORITHM : (Traversing of Linear Array) Here Arr is a linear array with lower bound L and upper bound U

1.[Initialize Counter] Set K=L.
2.Repeat steps 3 and 4 while K<=U
3.Print Arr[K].
4.[Increase Counter] Set K=K+1.
5.Exit

ALGORITHM :(Inserting into a Linear Array)   INSERT(Arr,N,K,ITEM)
Here Arr is a linear array with N elements ,K is positive integer such that K<=N and ITEM is the element to be inserted.

1.[Initialize Counter] Set I=N.
2.Repeat steps 3 and 4 while I>=K.
3.Set Arr[I+1]=Arr[I].
4. [Decrease Counter] Set I=I-1.
5.[Inserting ITEM] Set Arr[K]=ITEM.
6.[Reset Number Of Elements].Set N=N+1.
7.Exit

ALGORITHM :(Deleting From Linear Array)   DELETE(Arr,N,K)
Here Arr is a linear array with N elements ,K is positive integer such that K<=N and Kth element is to be deleted.

1.[Initialize Counter] Set I=K.
2.Repeat steps 3 and 4 while I=N-1.
3.Arr[I]=Arr=[I+1].
4.[Increase Counter]Set I=I+1.
5.[Reset Number Of Elements].Set N=N-1.
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.


Followers