0% found this document useful (0 votes)
2 views2 pages

Front Rear

The document explains the functioning of a queue using two variables: front and rear. It illustrates the process of inserting and deleting elements in an array-based queue of size 5, demonstrating the changes in front and rear pointers. The document concludes with the condition indicating that the queue is empty when front exceeds rear.

Uploaded by

doctoraseen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Front Rear

The document explains the functioning of a queue using two variables: front and rear. It illustrates the process of inserting and deleting elements in an array-based queue of size 5, demonstrating the changes in front and rear pointers. The document concludes with the condition indicating that the queue is empty when front exceeds rear.

Uploaded by

doctoraseen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Queue uses two variables

 front → points to the first element

 rear → points to the last element

Example using array queue (size = 5)

Step 1: Initially queue is empty

front = -1
rear = -1

Queue: [ _ _ _ _ _ ]

Empty condition.

Step 2: Insert element 10

front = 0
rear = 0

Queue: [ 10 _ _ _ _ ]

Step 3: Insert element 20

front = 0
rear = 1

Queue: [ 10 20 _ _ _ ]

Step 4: Delete one element

After deleting 10:

front = 1
rear = 1

Queue: [ _ 20 _ _ _ ]

Still one element exists.


Step 5: Delete another element

After deleting 20:

front = 2
rear = 1

Now observe carefully:

front > rear


2 > 1

This means queue is empty now.

Queue: [ _ _ _ _ _ ]

You might also like