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 to_list (self) method that returns all the elements from the

image text in transcribedpython please

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'l 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(q) print(a_list) de gueue: 5 9 Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 class 2 3 self. items _init__(self): [] def is_empty(self): 6 return self.__items == [] 8 def enqueue(self, item): 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): if len(self._items) == 0: 22 raise IndexError ("ERROR: The queue is empty!") 23 else: 24 return self.__items[len(self.__items)-1] def len__(self): return len(self.__items) def clear(self): return self.__items.clear() 32 def __str__(self): return "Queue: Front {} Rear".format(self.__items[::-1]) def multi_enqueue(self, element, how_many): for - in 'range (how_many) self.enqueue (element)

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 Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to the table in question

Answered: 1 week ago