Question: PYTHON 3 PLEASE FOLLOW INSTRUCTIONS Problem Given the LinkedList implementation we saw in class, complete the method reverse() to reverse the linked list. The method
PYTHON 3
PLEASE FOLLOW INSTRUCTIONS

Problem
Given the LinkedList implementation we saw in class, complete the method reverse() to reverse the linked list. The method operates on the linked list and doesn't return anything.
Code from picture:
class Node: def __init__(self, value): self.value = value self.next = None
class LinkedList: def __init__(self): self.first = None
def prepend(self, value): new_node = Node(value) new_node.next = self.first self.first = new_node def reverse(self): #TODO def printItems(self): current = self.first while current is not None: print(current.value, end=" ") current = current.next my_list = LinkedList() my_list.prepend("a") my_list.prepend("b") my_list.prepend("c") my_list.printItems() # should print "c b a" my_list.reverse() print() my_list.printItems() # should print "a b c"
Instructions from your teacher Problem Given the LinkedList implementation we saw in class, complete the method reverse() to 1 class Node 2 def init..(self, value): self.value value self.next None reverse the linked list. The method operates on the linked list and doesn't return anything 6 class LinkedList: def_init (self): self.first None 10 def prepend(self, value): new node Node(value) new node.next-self.first self.first new_node 12 13 14 15 def reverse(self): 16 17 18 def printItems(self): 19 20 21 current self.first while current is not None: print(current.value, end-" current current.next 23 24 my list - LinkedListO 25 my_list.prepend("a") 26 my_list.prependC"b") 27 my_list.prependC"c 28 my-list.printitems() # should print "c b a 29 my list.reverseC) 30 printO 31 my-list. printitems() # should print "a b c"1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
