Question: Priority Queue In Python please! Thank you so much! ### EX7_3 # Implement the class priorityQueue as discussed in class # In this exercise, code
Priority Queue In Python please! Thank you so much!
### EX7_3 # Implement the class priorityQueue as discussed in class # In this exercise, code the four functions # parent, leftChild, rightChild, and insert # # Submission # - Don't change the function names # - File name EX7_3.py
class priorityQueue: #The ADT PriorityQueue is implemented as a heap. #Need insert and deletemax as the supported functions def __init__(self): self.heap=[] # As discussed in class, # heap[1:n] is the body of the heap. # It's an ARRAY of integers # whose index range is 1:n, NOT 0:n-1 self.size = 0
def __len__(self): return self.size
def parent(index): # index is between 1 and self.size # It returns the value of the parent of heap[index] # If index<=1, it reutnrs None #---- code ------
def leftChild(index): # It returns the value of the left child #---- code -----
def rightChild(index): # It returns the value of the left child #---- code -----
def insert(x): # x is an integer, and the funciton just inserts # into self.heap, satisfying the heap property # It returns nothing just chaning the heap # --- code -----
#Test code h = priorityQueue() h.insert(10) h.insert(5) h.insert(14) h.insert(9) h.insert(2) h.insert(11) h.insert(6) print(h.heap)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
