Question 76
Consider the following Python class definition for a Linked List node:
class Node:
def __init__{self, val}:
self.val = val
self.next = Nonehead = Node(10)
head.next = Node(20)
head.next.next = Node(30)
# Code:
curr = head
s = 0
while curr:
s += curr.val
curr = curr.next
print(s)
The while loop traverses the 3 nodes with values 10, 20, 30. Sum = 10 + 20 + 30 = 60.