📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Complete the insert_at_beginning function for a singly

    linked list. Assume Node has data and next attributes. class Node:     def __init__(self, data):         self.data = data         self.next = None def insert_at_beginning(head, new_data):     new_node = Node(new_data)     _________ # Line to complete     return new_node # new_node becomes the new head
    A head = new_node Correct Answer Incorrect Answer
    B new_node.next = head Correct Answer Incorrect Answer
    C new_node.next = head.next Correct Answer Incorrect Answer
    D head.next = new_node Correct Answer Incorrect Answer
    E new_node.next = None Correct Answer Incorrect Answer

    Solution

    The correct answer is B

    Practice Next
    ask-question