Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node in a circular linked list.
DSA C
struct Node* newNode = (struct Node*) malloc(sizeof([1])); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a basic data type like int or char instead of the node struct.
Forgetting to cast the malloc return value.
✗ Incorrect
We allocate memory for a new node of type 'Node' to create a new node in the circular linked list.
2fill in blank
mediumComplete the code to check if the circular linked list is empty.
DSA C
if (head == [1]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing head to 0 or head->next instead of NULL.
Using assignment '=' instead of comparison '=='.
✗ Incorrect
The list is empty if the head pointer is NULL.
3fill in blank
hardFix the error in the code to delete the head node from a circular linked list.
DSA C
while (temp->next != [1]) { temp = temp->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking temp->next against head->next instead of head.
Using NULL in a circular list where no node points to NULL.
✗ Incorrect
To find the last node, we check where temp->next points to head, not head->next.
4fill in blank
hardFill both blanks to correctly update pointers when deleting the head node.
DSA C
temp->next = [1]; head = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting temp->next to head instead of head->next.
Not updating head to the new node.
✗ Incorrect
The last node's next pointer should point to the new head, which is head->next, and head should be updated to head->next.
5fill in blank
hardFill all three blanks to delete a node with a given key from the circular linked list.
DSA C
struct Node *prev = head; struct Node *curr = head->next; while (curr != head && curr->data != [1]) { prev = curr; curr = curr->[2]; } if (curr->data == [3]) { prev->next = curr->next; free(curr); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for key or next pointer.
Not checking the condition properly in the while loop.
✗ Incorrect
We compare curr->data with key, move curr to curr->next, and check again if curr->data equals key to delete the node.
