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;
newNode->prev = NULL; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or other pointers instead of the data value.
Forgetting to assign the data field.
✗ Incorrect
The new node's data field should be set to the given data value.
2fill in blank
mediumComplete the code to check if the list is empty.
DSA C
if (*head == [1]) { *head = newNode; return; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing head to newNode or other pointers.
Using assignment '=' instead of comparison '=='.
✗ Incorrect
If *head is NULL, the list is empty and the new node becomes the head.
3fill in blank
hardFix the error in the loop that finds the last node.
DSA C
struct Node* temp = *head; while (temp->[1] != NULL) { temp = temp->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using temp->prev which moves backward.
Checking temp->data instead of pointers.
✗ Incorrect
To find the last node, traverse while temp->next is not NULL.
4fill in blank
hardFill both blanks to link the new node at the end.
DSA C
temp->next = [1]; [2]->prev = temp;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Linking to head or temp incorrectly.
Not updating both next and prev pointers.
✗ Incorrect
The last node's next points to newNode, and newNode's prev points back to last node.
5fill in blank
hardFill all three blanks to complete the insert at end function.
DSA C
void insertEnd(struct Node** head, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = [1];
newNode->next = NULL;
newNode->prev = NULL;
if (*head == [2]) {
*head = newNode;
return;
}
struct Node* temp = *head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = [3];
newNode->prev = temp;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to dereference head pointer.
Linking temp->next to wrong node.
Not setting newNode->prev correctly.
✗ Incorrect
Assign data to newNode->data, check if *head is NULL, and link temp->next to newNode.
