1 1 vote Consider the following code fragment.class Node: def __init__(self, data, next=None): self.data = data self.next = next def invert_list(front): curr = front prev = None next = curr.next while curr is not None : (*) front = prev return front Which code must be added in the part marked (*) so the above code correctly inverts a non-empty singly linked list? See the figure to understand what ”invert” means. next.next = prev; prev = curr; curr = next; if next is not None: next = next.next curr.next = prev; prev = curr; curr = next_node; if next is not None: next = next.next next.next = curr; prev = curr; curr = next; if next is not None: next = next.next prev = curr; curr = next; curr.next = prev; if next is not None: next = next.next Data Structures goclasses_da_dsa_tw1 goclasses data-structures linked-list two-marks + – GO Classes 440 views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments mitaliii commented Nov 15, 2024 reply Follow flag In option B what is "next_node"? 3 3 replyShare Sang4567 commented Dec 10, 2024 reply Follow flag It cannot be option B as next_node is not defined anywhere in code. 1 1 replyShare Anup_Jeejo commented Dec 20, 2024 reply Follow flag @GO Classes I believe that option B cannot be the answer as there is an undefiend variable next_node which will set curr to None for next iteration and hence it will result in termination of loop in the next iteration. I think all the options are not correct and options need to be corrected 0 0 replyShare Please log in or register to add a comment.
3 3 votes $ I\, think \, that \, is \, printing \, mistake.$ $ if\, treated\, as \, next\, that\, is\, yeilding\, the \, Desired \, results.$ venkythecoder answered Jan 21 venkythecoder comment Share Follow 0 reply Please log in or register to add a comment.