Question

What will be the output of the following code when printList is called with a linked list containing the values 1 -> 2 -> 3? class Node:     def __init__(self, data):         self.data = data         self.next = None class LinkedList:     def __init__(self):         self.head = None     def append(self, data):         new_node = Node(data)         if not self.head:             self.head = new_node             return         last_node = self.head         while last_node.next:             last_node = last_node.next         last_node.next = new_node     def printList(self):         current = self.head         while current:             print(current.data, end=" -> ")             current = current.next         print("None") ll = LinkedList()
ll.append(1)
ll.append(2)
ll.append(3)
ll.printList()

A 1 -> 2 -> 3 -> None
B 1 -> None
C 2 -> 3 -> None
D 3 -> 2 -> 1 -> None
E None
Practice Next

Relevant for Exams:

Hey! Ask a query