Question: python please. I have uploaded the code, just need to add the add_all(self, a_list) function self.-_binary_heaptindap[index // 2] Continuing on from your implementation of the

python please. I have uploaded the code, just need to add thepython please. I have uploaded the code, just need to add the add_all(self, a_list) function

self.-_binary_heaptindap[index // 2] Continuing on from your implementation of the PriorityQueue class, add a method named add_all(self, a_list) in the PriorityQueue class. The method takes a Python list as a parameter and inserts all elements from the Python list into the binary heap. You must call the insert() method on each element in order to maintain the heap property in the binary min- heap. Note: Submit the entire class definition. Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. You can assume that the list is not empty. For example: Test Result pq = PriorityQueue () [0, 4, 5, 11, 9, 18] pq. add_all([9, 5, 11, 4, 18]) print(pq) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) 1 class PriorityQueue: 2 def __init__(self): self.__binary_heap [0] self.__size = 0 6 def str__(self): 7 return str(self.__binary_heap) 8 9 def Llen__(self): 10 return len(self.__binary_heap) - 1 11 12 def add_all_ignore-order(self, a_list): 13 14 self.__size = Lenca_list) 15 self.__binary_heap = [0] + a_list[:] 16 17 def percolate_up(self, index): 18 while index // 250: 19 if self.__binary_heap[index]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!