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

Data Structures Lab Assignment 6

The document outlines four activities related to circular queues: performing manual dry runs of operations, implementing a circular queue in Python, simulating a real-life printer queue scenario, and debugging a faulty circular queue implementation. Each activity includes specific tasks and examples to guide the user through understanding and applying circular queue concepts. The focus is on both theoretical understanding and practical coding skills.

Uploaded by

prisha.kashyap24
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)
4 views

Data Structures Lab Assignment 6

The document outlines four activities related to circular queues: performing manual dry runs of operations, implementing a circular queue in Python, simulating a real-life printer queue scenario, and debugging a faulty circular queue implementation. Each activity includes specific tasks and examples to guide the user through understanding and applying circular queue concepts. The focus is on both theoretical understanding and practical coding skills.

Uploaded by

prisha.kashyap24
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
You are on page 1/ 2

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):
self.size = size
self.queue = [None] * size
self.front = self.rear = -1

def enqueue(self, value):


if (self.rear + 1) % self.size == self.front:
print("Queue is full!")
return
self.rear = (self.rear + 1) % self.size
self.queue[self.rear] = value

def dequeue(self):
if self.front == self.rear:
print("Queue is empty!")
return
self.front = (self.front + 1) % self.size
return self.queue[self.front]

Find and correct the mistakes. Test cases should include different enqueue and dequeue scenarios.

You might also like