Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python please Continuing on from the previous question, extend the Queue class by adding the multi_enqueue (self, element, how_many) method which enqueues the parameter element

image text in transcribedimage text in transcribedpython please

Continuing on from the previous question, extend the Queue class by adding the multi_enqueue (self, element, how_many) method which enqueues the parameter element to the queue the number of times specified by the parameter how_many. Submit the entire Queue class definition in the answer box below. You can assume that the parameter how_many > 0. Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result Queue: Front ['Audi', 'Honda', 'Toyota', 'Mercedes', 'Mercedes'] Rear carBrand = Queue () carBrand.enqueue ('Audi') carBrand. enqueue ('Honda') carBrand. enqueue ('Toyota') carBrand.multi_enqueue ('Mercedes', 2) print(carBrand) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 class Queue: 2 def __init__(self): self._items [] def is_empty(self): return self.__items 07 def enqueue(self, item): 9 self.__items. insert(0, item) 10 11 def dequeue(self): 12 if 'len(self. -_items) 0: 13 raise IndexError ("ERROR: The queue is empty!") 14 else: 15 return self.__items.pop() 16 17 def size(self): 18 return len(self.__items) 19 20 def peek(self): 21 if len(self. items) 0: 22 raise IndexError ("ERROR: The queue is empty!") 23 else: 24 return self.__items[len(self.__items)-1] 25 26 def __len__(self) 27 return len(self.__items) 28 29 def clear(self): 30 return self._items.clear() 31 32 def __str__(self): 33 return "Queue: Front {} Rear".format(self.__items[::-1]) 34 Continuing on from the previous question, extend the Queue class by adding the to_list(self) method that returns all the elements from the queue as a new Python List. The function should copy elements from the front and append them to a new list. However, the function should not modify the content in the queue. Submit the entire Queue class definition. For example: Test Result car_brand = Queue () Python List: ['Audi', 'Honda', 'Toyota', 'Mercedes'] car_list = ['Audi', 'Honda', 'Toyota', 'Mercedes'] Queue: Front ['Audi', 'Honda', 'Toyota', 'Mercedes'] Rear for item in car_list: car_brand.enqueue (item) print("Python List:", car_brand.to_list()) print(car_brand) Queue: Front ['hello', 'world'] Rear ['hello', 'world', 1] q = Queue () q.enqueue('hello') q.enqueue ( 'world') a_list = q.to_list() a_list.append(1) print(9) print(a_list)

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

=+c) What is the probability that a person who is rejected by

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago

Question

What did they do? What did they say?

Answered: 1 week ago