Question: In the space below, write a Python method in the LinkedList class implementation with a head reference as discussed in lecture and the textbook called

In the space below, write a Python method in the LinkedList class implementation with a head reference as discussed in lecture and the textbook called (remove Index(self, index) ). This method will remove the element at the index position index O will refer to the first element that self.head refers to, index 1 will refer to the second element, etc.). To simplify the problem, you may assume that an element at the index position will always exist in the Linked List, and the Linked List nodes will only contain strings. For reference, the relevant pieces used in the test cases below (including a helper method constructing a string containing the elements in the Linked List from front to back for illustration purposes) are: class Node: de _init__(self, data): sel.data - data self.next - None def getData(self): return self.data def getNext(self): return self.next de setData(self, newData)! , : self.data - newData def setNext(self, newNext): Belf.next - newNext elass LinkedList: def __init__(self): sel.head - None def addToFront (self, item): temp - Node(item) temp.setNext(self.head) sel.head - temp # Helper Method returns string containing #elements in Linked List from front to back def getList(self) current - self. head output - while current ! - None: output - current.getData() + . current -current.getNext() output - output[:len (output)-1] # remove end space return output # Other LinkedList methods... Your solution should be a complete method definition with appropriate syntax and indentation If your method is implemented correctly, then the following pytest function should pass: def test_remove Index(): 11 - LinkedList() 11.addToFront("weekend!") 11.addToFront("great") 11.addToFront("a") 11.addToFront("Have") assert 11.getList() -- "Have a great weekend." 11.remove Index ( 2 ) assert 11.getList() -- "Have a weekend!" 11.remove Index (0) assert 11.getList() -- "a weekend! 11. remove Index (1) assert 11.getList() -- 11.remove Index (0) assert 11.getList()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
