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 =

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

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!