Question: PYTHON HELP NEEDED class PriorityQueue: def __init__(self,values=[]): self.binary_heap = [0] self.size = 0 for i in values: self.insert (i) def __str__(self): return str(self.binary_heap) def __len__(self):
PYTHON HELP NEEDED
class PriorityQueue:
def __init__(self,values=[]): self.binary_heap = [0] self.size = 0 for i in values: self.insert (i)
def __str__(self): return str(self.binary_heap)
def __len__(self): return self.size
def percolate_up(self, i): while i // 2 > 0 and self.binary_heap[i]
def get_smaller_child_index(self, i): if i * 2 + 1 > self.size: return i * 2 else: if self.binary_heap[i*2]
def percolate_down(self, i): while (i * 2) self.binary_heap[mc]: self.binary_heap[mc], self.binary_heap[i] = self.binary_heap[i], self.binary_heap[mc] i = mc
def insert(self, item): self.binary_heap.append(item) self.size += 1 self.percolate_up(self.size) def get_mininum(self): return self.binary_heap[1]
![PYTHON HELP NEEDED class PriorityQueue: def __init__(self,values=[]): self.binary_heap = [0] self.size =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f90252c22a7_09066f9025255f4c.jpg)
Continuing on from your implementation of the Prior ityQueue class, add the method named peek (self) which returns the element with the highest priority, without modifying the priority queue. If the priority queue is empty, it should return None. Notes: - The method should not modify any values in the binary heap. - Submit the entire class definition
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
