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


    Question

    Given the `SinglyLinkedList` and its `delete_node`

    method as provided, what will be the output of `my_list.print_list()` after the following sequence of operations? my_list = SinglyLinkedList() my_list.append(10) my_list.append(20) my_list.append(30) my_list.append(40) my_list.delete_node(10) my_list.delete_node(30) my_list.print_list()
    A 20 -> 40 Correct Answer Incorrect Answer
    B 20 -> 30 -> 40 Correct Answer Incorrect Answer
    C 10 -> 20 -> 40 Correct Answer Incorrect Answer
    D 10 -> 20 -> 30 -> 40 Correct Answer Incorrect Answer

    Solution

    Deleting 10 (head) works correctly, making the list 20 -> 30 -> 40. Attempting to delete 30 (non-head) triggers the error, and the prev.next pointer (from 20 to 30) is not updated. The list remains 20 -> 30 -> 40.

    Practice Next
    ask-question