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->prev = NULL;
newNode->next = NULL; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a pointer variable instead of the data value.
Assigning position or temporary node instead of data.
✗ Incorrect
The new node's data field should be assigned the value passed as 'data'.
2fill in blank
mediumComplete the code to insert the new node at the beginning of the list.
DSA C
if (pos == 1) { newNode->next = [1]; if (head != NULL) { head->prev = newNode; } head = newNode; return head; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode->next to itself.
Setting newNode->next to NULL incorrectly.
✗ Incorrect
The new node's next pointer should point to the current head node.
3fill in blank
hardFix the error in updating the previous pointer of the node after the new node.
DSA C
newNode->next = temp->next; if (temp->next != NULL) { temp->next->[1] = newNode; } temp->next = newNode; newNode->prev = temp;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating the next pointer instead of prev.
Not checking if temp->next is NULL before updating.
✗ Incorrect
The previous pointer of the node after newNode should point back to newNode.
4fill in blank
hardFill both blanks to traverse to the node before the insertion position.
DSA C
struct Node* temp = head; for (int i = 1; i < [1] - 1; i++) { temp = [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop limit or variable.
Moving temp incorrectly.
✗ Incorrect
We loop until the node before position 'pos', moving temp to temp->next each time.
5fill in blank
hardFill all three blanks to insert the new node at the given position in the doubly linked list.
DSA C
newNode->next = [1]; if ([2] != NULL) { [3]->prev = newNode; } temp->next = newNode; newNode->prev = temp;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of temp->next.
Not updating prev pointer of the next node.
✗ Incorrect
The new node's next points to temp->next; if temp->next is not NULL, its prev points to newNode.
