Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

existing code class CircularQueue: def __init__(self, capacity = 8): self.capacity = capacity self.front = 0 self.count = 0 self.back = capacity - 1 self.items =

image text in transcribed

existing code

class CircularQueue:

def __init__(self, capacity = 8):

self.capacity = capacity

self.front = 0

self.count = 0

self.back = capacity - 1

self.items = [None] * capacity

def __str__(self):

a_list = []

for i in range(self.count):

j = (self.back - i) % len(self.items)

item = self.items[j]

a_list.append(item)

return '-> |{}| ->'.format(', '.join([repr(item) for item in a_list]))

def enqueue(self, item):

if not self.is_full():

self.back = (self.back + 1) % self.capacity

self.items[self.back] = item

self.count += 1

else:

raise IndexError('ERROR: The queue is full.')

def dequeue(self):

if not self.is_empty():

item = self.items[self.front]

self.front = (self.front + 1) % self.capacity

self.count -= 1

return item

else:

raise IndexError('ERROR: The queue is empty.')

def is_empty(self):

return self.count == 0

def is_full(self):

return self.count == self.capacity

def create_new_circular_queue(self, number):

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago