[Solved]Total Complete Code Question 5 110 Marks Total Conm Similarly Examples Discussed Lectures Q37247932
Python
total – Complete the Code Question 5. 110 marks total- Conm Similarly to the examples discussed during lectures, the incomplete code below defines a class of Node objects and a class of LinkedList objects. Each Node object has the two attributes we saw in class and an additional third attribute: cargo (of type string), nextr (of type Node), and prioriry (of type integer). An object of type LinkedList is a collection of Node objects that are “linked” to cach other, i.e., each element contains a reference to its successor Complete the methods in parts A, B and C according to their docstrings by writing code in the boxes provided. When writing your code, you can use any of the methods given in the definition of the LinkedL.ist class class Node: def-init-(self, c-None, p-None): “‘Creates an object of type Node.” self. cargo c self.priority- P self.next None class LinkedList: def init (self): – — create a linked list, i.e., an object of type Linkedlist. This list is empty self. length . 0 # the number of elements in the list self.head None def insert in front (self, cargo, priority) (LinkedList)>NoneType Insert an element at the front of the list f self.length0 self.head Node (cargo, priority else: auxself.head self.head Node (cargo, pziority self.head.next-aux self.length1 def insert after node (self, n. cargo, priority): (LinkedList)->NoneType Insert an element in the list, right after node n auxn.next n.next-Node (c, priority) n. next next = aux self. length += 1 Part (A) [2 marks] def is_empty (self): (LinkedListbool Return True if the list is empty and False otherwise Part (B) 3 marks] def extract first (self) (LinkedList)-string or NoneType If the 1ist has at least one element, remove the first element from the list, return its cargo and assign the next node in the sequence to be the new head of the list. If the 1ist has only one element, remove the element and return its cargo. Return None if the list is empty.(N element removal is performed in this case Show transcribed image text total – Complete the Code Question 5. 110 marks total- Conm Similarly to the examples discussed during lectures, the incomplete code below defines a class of Node objects and a class of LinkedList objects. Each Node object has the two attributes we saw in class and an additional third attribute: cargo (of type string), nextr (of type Node), and prioriry (of type integer). An object of type LinkedList is a collection of Node objects that are “linked” to cach other, i.e., each element contains a reference to its successor Complete the methods in parts A, B and C according to their docstrings by writing code in the boxes provided. When writing your code, you can use any of the methods given in the definition of the LinkedL.ist class class Node: def-init-(self, c-None, p-None): “‘Creates an object of type Node.” self. cargo c self.priority- P self.next None class LinkedList: def init (self): – — create a linked list, i.e., an object of type Linkedlist. This list is empty self. length . 0 # the number of elements in the list self.head None def insert in front (self, cargo, priority) (LinkedList)>NoneType Insert an element at the front of the list f self.length0 self.head Node (cargo, priority else: auxself.head self.head Node (cargo, pziority self.head.next-aux self.length1 def insert after node (self, n. cargo, priority): (LinkedList)->NoneType Insert an element in the list, right after node n auxn.next n.next-Node (c, priority) n. next next = aux self. length += 1
Part (A) [2 marks] def is_empty (self): (LinkedListbool Return True if the list is empty and False otherwise Part (B) 3 marks] def extract first (self) (LinkedList)-string or NoneType If the 1ist has at least one element, remove the first element from the list, return its cargo and assign the next node in the sequence to be the new head of the list. If the 1ist has only one element, remove the element and return its cargo. Return None if the list is empty.(N element removal is performed in this case
Expert Answer
Answer to total – Complete the Code Question 5. 110 marks total- Conm Similarly to the examples discussed during lectures, the inc… . . .
OR

