Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node and insert it at the beginning of the linked list.
DSA C
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
new_node->data = data;
new_node->next = [1];
head = new_node; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node->next to NULL loses the rest of the list.
Setting new_node->next to new_node creates a cycle.
✗ Incorrect
To insert at the beginning, the new node's next should point to the current head.
2fill in blank
mediumComplete the code to update the head pointer after inserting the new node at the beginning.
DSA C
new_node->next = head;
[1] = new_node; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to temp or next causes errors.
Not updating head leaves the list unchanged.
✗ Incorrect
After insertion, head should point to the new node.
3fill in blank
hardFix the error in the code that inserts a new node at the beginning of the list.
DSA C
struct Node* new_node = malloc(sizeof(struct Node));
new_node->data = data;
new_node->next = [1];
head = new_node; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using head->next loses the first node.
Setting next to NULL breaks the chain.
✗ Incorrect
The new node's next must point to the current head, not head->next or NULL.
4fill in blank
hardFill both blanks to correctly insert a new node at the beginning and update the head pointer.
DSA C
struct Node* new_node = malloc(sizeof(struct Node)); new_node->data = data; new_node->next = [1]; [2] = new_node;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of assignments.
Using wrong variable names.
✗ Incorrect
The new node's next points to head, and head is updated to new_node.
5fill in blank
hardFill all three blanks to create a new node, link it at the beginning, and update the head pointer.
DSA C
struct Node* [1] = malloc(sizeof(struct Node)); [1]->data = data; [1]->next = [2]; [3] = [1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names.
Not updating head pointer.
✗ Incorrect
Create new_node, set its next to head, then update head to new_node.
