Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with given data.
DSA C
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = [1];
newNode->next = NULL; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or pointer variables instead of data to newNode->data.
✗ Incorrect
The new node's data field should be set to the given data value.
2fill in blank
mediumComplete the code to handle the case when the list is empty.
DSA C
if (head == NULL) { newNode->next = newNode; head = [1]; return head; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to NULL or an unrelated pointer.
✗ Incorrect
When the list is empty, head should point to the new node.
3fill in blank
hardFix the error in the loop that finds the last node.
DSA C
struct Node* temp = head; while (temp->next != [1]) { temp = temp->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for NULL instead of head in the loop condition.
✗ Incorrect
In a circular linked list, the last node points back to head, not NULL.
4fill in blank
hardFill both blanks to insert the new node at the end and maintain circularity.
DSA C
temp->next = [1]; newNode->next = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Breaking the circular link by pointing to NULL or wrong nodes.
✗ Incorrect
The last node should point to the new node, and the new node should point back to head.
5fill in blank
hardFill all three blanks to complete the insert function returning the updated head.
DSA C
struct Node* insertEnd(struct Node* head, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
if (head == NULL) {
newNode->next = newNode;
head = [1];
return head;
}
struct Node* temp = head;
while (temp->next != [2]) {
temp = temp->next;
}
temp->next = [3];
newNode->next = head;
return head;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of head in the loop condition.
Not linking the last node to the new node.
✗ Incorrect
Assign head to newNode when list is empty; loop until temp->next is head; link temp->next to newNode.
