Professional Documents
Culture Documents
Dequeue
Remove an element from the front of the queue
Remove Insert
(Dequeue) front rear (Enqueue)
ALGORITHM TO INSERT DATA
IN A QUEUE
FRONT = -1, REAR = -1, TO REPRESENT QUEUE IS EMPTY
INSERT(QUEUE[N],FRONT,REAR,ITEM)
{ //QUEUE is an array of size N ,ITEM is element to be inserted.
1. if (REAR == N-1)
1.1 Print “OVERFLOW”
else
1.1 if (FRONT == -1)
1.1.1 FRONT = 0
1.2 REAR = REAR+1
ALGORITHM TO DELETE DATA
FROM A QUEUE
DELETE(QUEUE[N],ITEM,FRONT,REAR)
{
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
IMPLEMENTING A QUEUE
USING ARRAY
Front:2, Rear:6 QUEUE
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
ACTIVITY
Consider the given list working as QUEUE, perform the given instructions in given queue.
1. Enqueue(4)
2. Enqueue(9)
3. Enqueue(33)
4. Dequeue()
5. Enqueue(20)
6. Dequeue()
7. What is the location of Front and rear?? (Assuming indexing starts from 1)
CIRCULAR QUEUE (RING
BUFFER)
Suppose we want to insert an element into the queue after it occupies the last part
of the array i.e. REAR=n.
One way of doing it is simply move the entire queue to the beginning of the array,
changing FRONT and REAR, and then inserting the element. This procedure may
be very expensive.
This can be done assuming that the array QUEUE is circular that is the QUEUE[1]
comes after QUEUE[N] in the array. Instead if increasing REAR to N+1 we reset
REAR=1.
CIRCULAR QUEUE
ALGORITHM TO INSERT DATA IN A CIRCULAR
QUEUE