0% found this document useful (0 votes)
4 views3 pages

Linear Queue Operations and Rules

The document outlines the rules for managing a linear queue using an array, including initialization, enqueue, and dequeue operations. It explains the conditions for overflow and underflow, emphasizing that overflow occurs when the rear reaches the maximum size of the queue, preventing further insertions despite available space. A simulation sequence illustrates the queue operations and their effects on the front and rear pointers.

Uploaded by

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

Linear Queue Operations and Rules

The document outlines the rules for managing a linear queue using an array, including initialization, enqueue, and dequeue operations. It explains the conditions for overflow and underflow, emphasizing that overflow occurs when the rear reaches the maximum size of the queue, preventing further insertions despite available space. A simulation sequence illustrates the queue operations and their effects on the front and rear pointers.

Uploaded by

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

Queue Rules (Linear Queue with array)

• Initialize:
o front = -1
o rear = -1
• Enqueue (Insert) rules:
o If rear == SIZE - 1, overflow occurs (queue full).
o Else if queue is empty (front == -1), set front = 0.
o Increment rear by 1.
o Insert element at queue[rear].
• Dequeue (Delete) rules:
o If queue is empty (front == -1 or front > rear), underflow occurs (queue
empty).
o Else remove element at queue[front].
o Increment front by 1.
o If front > rear, reset front = rear = -1 (queue empty).

Why does Overflow happen in a Linear Queue?


• Even if some elements are dequeued at the front, rear can’t move backward or wrap
around.
• Once rear reaches SIZE - 1, no more elements can be inserted (overflow), even if there
is free space at the front.
Simulation Sequence:

enqueue(10), enqueue(20), dequeue(), enqueue(30), enqueue(40),


enqueue(50), enqueue(60), display, dequeue x4, dequeue

Array_size = 5

Queue Operation Table (C-style Linear Queue)

Step Operation front rear Queue Action / Condition


Content
1. -1 -1 [_, _, _, _, _]

2. enqueue(10) 0 0 [10, _, _, _, _] First insertion: front & rear set to 0

3. enqueue(20) 0 1 [10, 20, _, _, _] rear++

4. dequeue() 1 1 [_, 20, _, _, _] front++

5. enqueue(30) 1 2 [_, 20, 30, _, _] rear++

6. enqueue(40) 1 3 [_, 20, 30, 40, rear++


_]
7. 6 enqueue(50) 1 4 [_, 20, 30, 40, rear++
50]
8. 7 enqueue(60) 1 4 [_, 20, 30, 40, ❌ Overflow: rear == SIZE - 1
50]
9. 8 display() 1 4 [20, 30, 40, 50] Show from front to rear

10. 9 dequeue() 2 4 [_, _, 30, 40, front++


50]
11. 10 dequeue() 3 4 [_, _, _, 40, 50] front++

12. 11 dequeue() 4 4 [_, _, _, _, 50] front++

13. 12 dequeue() -1 -1 [_, _, _, _, _] ✅ Queue empty → Reset pointers

14. 13 dequeue() -1 -1 [_, _, _, _, _] ❌ Underflow: front == -1

You might also like