B. n2->next should point to n1 to make the list circular.
C. Data values are not initialized correctly.
D. n1->next should be NULL instead of n2.
Solution
Step 1: Identify the circular link requirement
In a circular singly linked list, the last node's next pointer must point back to the first node.
Step 2: Check the code's next pointers
n1->next points to n2, but n2->next is NULL, breaking the circle. It should point to n1.
Final Answer:
n2->next should point to n1 to make the list circular. -> Option B
Quick Check:
Last node next points to head = D [OK]
Hint: Last node's next must link to first node [OK]
Common Mistakes:
Setting last node next to NULL instead of head
Forgetting to allocate memory for nodes
Mixing up which node points where
5. You want to insert a new node with data 5 at the end of an existing circular singly linked list. The list currently has nodes 1 -> 2 -> 3 -> (back to 1). Which steps correctly insert the new node to maintain the circular structure?
hard
A. Create new node; set new_node->next = head; find last node; set last_node->next = new_node;
B. Create new node; set new_node->next = NULL; find last node; set last_node->next = new_node;
C. Create new node; set new_node->next = last_node; set head = new_node;
D. Create new node; set new_node->next = head->next; set head->next = new_node;
Solution
Step 1: Create new node and link it to head
The new node's next pointer must point to the head to keep the circle intact.
Step 2: Find the last node and update its next pointer
Traverse the list to find the last node (which points to head), then set last_node->next to new_node.
Final Answer:
Create new node; set new_node->next = head; find last node; set last_node->next = new_node; -> Option A
Quick Check:
New node next = head, last node next = new node = A [OK]
Hint: New node next points to head; last node next points to new node [OK]
Common Mistakes:
Setting new node next to NULL breaks circularity
Not updating last node's next pointer
Confusing head and last node pointers
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.