C. Loop runs one time too many causing temp to be NULL
D. Head pointer is not updated after insertion
Solution
Step 1: Analyze loop for position 2
Loop should run from i=1 to i < pos-1 to stop at node before insertion point.
Step 2: Check temp usage after loop
Original loop runs one time too many, moving temp to node 2 instead of node 1, causing incorrect insertion or NULL access.
Final Answer:
Loop runs one time too many causing temp to be NULL -> Option C
Quick Check:
Loop overshoots node before position [OK]
Hint: Loop should stop at position-1 to avoid NULL [OK]
Common Mistakes:
Loop runs to pos instead of pos-1
Not checking for NULL before accessing temp->next
Forgetting to allocate memory for new node
5. You have a singly linked list with 5 nodes: 1 -> 2 -> 3 -> 4 -> 5 -> NULL. You want to insert a node with value 99 at position 6. What should happen and what will be the final list?
hard
A. Node 99 is appended at the end; list becomes 1 -> 2 -> 3 -> 4 -> 5 -> 99 -> NULL
B. Node 99 is inserted at position 5; list becomes 1 -> 2 -> 3 -> 4 -> 99 -> 5 -> NULL
C. Node 99 replaces node 5; list becomes 1 -> 2 -> 3 -> 4 -> 99 -> NULL
D. Insertion fails because position 6 is invalid; list remains unchanged
Solution
Step 1: Check list length and position
List has 5 nodes; position 6 means insert after last node (append).
Step 2: Insert node at end
Since position is one more than length, node 99 is added after node 5.
Final Answer:
Node 99 is appended at the end; list becomes 1 -> 2 -> 3 -> 4 -> 5 -> 99 -> NULL -> Option A
Quick Check:
Insert at pos > length means append [OK]
Hint: Position beyond length means append at end [OK]
Common Mistakes:
Rejecting valid append position
Replacing last node instead of appending
Inserting at wrong position due to off-by-one
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.