Question: (c) (10 marks) Edit the insert function in the code below to convert your algorithm into Python code. You must observe the coding style guidance

(c) (10 marks)

Edit the insert function in the code below to convert your algorithm into Python code. You must observe the coding style guidance in Chapter 5.3 and Chapter 10.3.

In [ ]:

class CinemaPriorityQueue:
 """A linked list implementation of an unbounded min-priority queue."""
 
 class Node:
 """A node in a linked list."""
 
 def __init__(self, item: object, priority_value: int) -> None:
 """Initialise the node with the given item and priority value."""
 self.item = item
 self.priority = priority_value
 self.next = None
 
 def __init__(self) -> None:
 """Initialise the queue to be empty."""
 self.head = None
 
 def is_empty(self) -> bool:
 """
 Preconditions: true
 Postconditions: the output is true if the queue is empty, false otherwise
 """
 return self.head == None
 
 def print(self) -> None:
 """Print out the queue"""
 if self.head == None:
 print('The queue is empty')
 else:
 current = self.head
 while current != None:
 print(current.item, current.priority)
 current = current.next
 
 def insert(self, item: object, priority_value: int) -> None:
 """Insert item according to priority.
 Preconditions: true
 Postconditions: post-self is the sequence
 pre-self with item inserted after
 the last item in self with the same priority
 """
 pass
 #*Write your code solution here*
 
                        

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!