3 3 votes Consider the following Python code:class Node: def __init__(self, data): self.data = data self.next = None head = Node(20) tail = head new_first = Node(10) new_first.next = head head = new_first new_last = Node(30) tail.next = new_last tail = new_last print(head.data, head.next.data, tail.data, head.next.next.data)What is the output of the code above?10 20 30 3020 10 30 3010 30 30 2010 20 20 30 Programming in Python goclasses goclasses-da-dpp goclasses-da-dpp-day-211 programming-in-python goclasses-python-&-dsa-practice-questions output linked-list + – GO Classes 183 views answer comment Share Follow Print See 1 comment 1 1 comment reply Mohd_Arquam_Khan commented Jul 6 reply Follow flag the chain: 10 -> 20 -> 30 after execution of code at 10 : Head at 30 : tail now head.data > 10 head.next.data >20 tail.data > 30 head.next.next.data > 30 Ans: Option A:10 20 30 30 0 0 replyShare Please log in or register to add a comment.
1 1 vote Initially:head -> 20 tail -> 20Now a new node is inserted at the beginning:new_first = Node(10) new_first.next = head head = new_firstSo the list becomes:10 -> 20The tail is still pointing to node $20$.Now a new node is inserted at the end:new_last = Node(30) tail.next = new_last tail = new_lastSo the list becomes:10 -> 20 -> 30Therefore:head.data = 10 head.next.data = 20 tail.data = 30 head.next.next.data = 30The output is:10 20 30 30Correct Option: A GO Classes answered Jun 29 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.