Please help with a python script that can run the following thanks for your help
ID: 3759986 • Letter: P
Question
Please help with a python script that can run the following thanks for your help!
Write a container class called PriorityQueue. The class should support methods:
• insert(): Takes a number as input and adds it to the container
• min(): Returns the smallest number in the container
• removeMin(): Removes the smallest number in the container
• isEmpty(): Returns True if container is empty, False otherwise
The overloaded operator len() should also be supported.
>>> pq = PriorityQueue()
>>> pq.insert(3)
>>> pq.insert(1)
>>> pq.insert(5)
>>> pq.insert(2)
>>> pq.min()
1
>>> pq.removeMin()
>>> pq.min()
2
>>> len(pq) 3
>>> pq.isEmpty()
False
Explanation / Answer
>>> pq = PriorityQueue()
>>> pq.insert(3)
>>> pq.insert(1)
>>> pq.insert(5)
>>> pq.insert(2)
>>> pq.min()
1
>>> pq.removeMin()
>>> pq.min()
2
>>> len(pq) 3
>>> pq.isEmpty()
False
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.