0% found this document useful (0 votes)
25 views

Queue Operations Work As Follows

A queue uses two pointers called FRONT and REAR to keep track of the first and last elements, with FRONT and REAR initialized to -1. Enqueuing increases REAR and places an element at that index, while dequeuing returns and removes the element at FRONT before increasing FRONT.

Uploaded by

zaheer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Queue Operations Work As Follows

A queue uses two pointers called FRONT and REAR to keep track of the first and last elements, with FRONT and REAR initialized to -1. Enqueuing increases REAR and places an element at that index, while dequeuing returns and removes the element at FRONT before increasing FRONT.

Uploaded by

zaheer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

How Queue Works

Queue operations work as follows:

1. Two pointers called FRONT and REAR are used to keep


track of the first and last elements in the queue.
2. When initializing the queue, we set the value
of FRONT and REAR to -1.
3. On enqueuing an element, we increase the value
of REAR index and place the new element in the position
pointed to by REAR.
4. On dequeuing an element, we return the value pointed to
by FRONT and increase the FRONT index.
5. Before enqueuing, we check if the queue is already full.

6. Before dequeuing, we check if the queue is already


empty.

7. When enqueuing the first element, we set the value


of FRONT to 0.
8. When dequeuing the last element, we reset the values
of FRONT and REAR to -1.

You might also like