Assignment 6:
Activity 1: Manual Dry Run of Circular Queue Operations
Given a circular queue of size N, manually perform the following operations:
Enqueue elements until the queue is full.
Dequeue a few elements.
Enqueue more elements and observe how they wrap around.
Identify the front and rear after each operation.
Example: If the queue size is 5, perform:
Enqueue(10) → Enqueue(20) → Enqueue(30) → Dequeue() → Enqueue(40) → Enqueue(50) → Enqueue(60).
Track Front and Rear at each step.
Activity 2: Implement Circular Queue from Scratch
Write a Python program to implement a circular queue using an array with the following operations:
enqueue(value): Insert an element.
dequeue(): Remove an element.
peek(): Display the front element.
is_empty(): Check if the queue is empty.
is_full(): Check if the queue is full.
Implement it without using built-in list functions like append() or pop().
Activity 3: Solve a Real-Life Scenario Using Circular Queue
Problem: A printer queue follows a circular queue system. Assume a printer processes documents in order of arrival.
Tasks:
Simulate a queue where multiple users send documents to print.
Implement enqueue when a new document arrives and dequeue when a document is printed.
Display the status of the queue after each operation.
Activity 4: Circular Queue Debugging Challenge
You will be given a faulty implementation of a circular queue. Debug and fix errors to ensure it follows circular queue
rules.
Example of an incorrect implementation:
class CircularQueue:
def __init__(self, size):
[Link] = size
[Link] = [None] * size
[Link] = [Link] = -1
def enqueue(self, value):
if ([Link] + 1) % [Link] == [Link]:
print("Queue is full!")
return
[Link] = ([Link] + 1) % [Link]
[Link][[Link]] = value
def dequeue(self):
if [Link] == [Link]:
print("Queue is empty!")
return
[Link] = ([Link] + 1) % [Link]
return [Link][[Link]]
Find and correct the mistakes. Test cases should include different enqueue and dequeue scenarios.