Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We have provided a print operation print() that you can use to print out the queue. Test your code. You may use additional print statements

We have provided a print operation print() that you can use to print out the queue. Test your code. You may use additional print statements to explain what you are testing with each test. Make sure you test for each of the three cases:

  • insert into an empty queue
  • insert at the front of the queue
  • insert after some existing node.

------------

QUESTION BEFORE

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Explain the chemical properties of acids with examples.

Answered: 1 week ago

Question

Write the properties of Group theory.

Answered: 1 week ago

Question

3. Is there opportunity to improve current circumstances? How so?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago