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()
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()
More Basics of Computers Questions
- Which of the following is a critical component of a data protection policy that supports regulatory compliance?
- Which of the following algorithms is the most efficient for finding the smallest element in an unsorted array?
- Which of the following correctly describes the second normal form (2NF) in database normalization?
- What is the primary function of the OSI model's transport layer?
- In the context of Cross-Site Scripting (XSS), what is the primary reason why stored XSS is considered more dangerous than reflected XSS?
- Purpose of Scope resolution operator
- Data mart types
- Which of the following types of networks is most suitable for securely connecting geographically distant branches of a multinational company, while ensurin...
- In Git, what does the git pull command do?
- What is the role of Artificial Intelligence (AI) in modern business applications?
Relevant for Exams:
Hey! Ask a query
Please enter email id
The email must be a valid email address.
Please enter Mobile Number
Please enter valid Mobile Number
Please enter your Doubt