3. Given the following code snippet to clone a linked list with random pointers, what will be the output of the print statement?
class Node:
def __init__(self, val, next=None, random=None):
self.val = val
self.next = next
self.random = random
def print_list(head):
curr = head
result = []
while curr:
rand_val = curr.random.val if curr.random else None
result.append((curr.val, rand_val))
curr = curr.next
print(result)
# Original list
node1 = Node(1)
node2 = Node(2)
node3 = Node(3)
node1.next = node2
node2.next = node3
node1.random = node3
node2.random = node1
node3.random = node2
# Cloned list (shallow copy for example)
clone1 = Node(1)
clone2 = Node(2)
clone3 = Node(3)
clone1.next = clone2
clone2.next = clone3
clone1.random = node3
clone2.random = node1
clone3.random = node2
print_list(clone1)