Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a pointer to the next node in a linked list node structure.
DSA C
struct Node {
int data;
struct Node* [1];
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using generic names like 'pointer' which are unclear.
✗ Incorrect
The pointer to the next node in a linked list is conventionally named 'next'.
2fill in blank
mediumComplete the code to create a new node and assign its data field.
DSA C
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->[1] = 10;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to assign to 'value' or 'info' which are not declared fields.
Assigning to 'next' which is a pointer, not data.
✗ Incorrect
The data field in the node structure is named 'data', so we assign the value to newNode->data.
3fill in blank
hardFix the error in the code to correctly link two nodes in a singly linked list.
DSA C
struct Node* first = (struct Node*)malloc(sizeof(struct Node)); struct Node* second = (struct Node*)malloc(sizeof(struct Node)); first->data = 1; second->data = 2; first->[1] = second;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using undefined pointer names like 'link' or 'pointer'.
✗ Incorrect
To link the first node to the second, assign the 'next' pointer of the first node to point to the second node.
4fill in blank
hardFill both blanks to declare a doubly linked list node structure with pointers to previous and next nodes.
DSA C
struct Node {
int data;
struct Node* [1];
struct Node* [2];
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'link' or 'pointer' which are not standard names.
Mixing up the order of 'prev' and 'next'.
✗ Incorrect
In a doubly linked list, nodes have 'prev' pointer to the previous node and 'next' pointer to the next node.
5fill in blank
hardFill all three blanks to create a function that initializes a new node with given data and sets its pointers to NULL.
DSA C
struct Node* createNode(int value) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->[1] = value;
newNode->[2] = [3];
return newNode;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning value to 'next' or 'prev' instead of 'data'.
Not initializing pointers to NULL.
✗ Incorrect
The function sets the 'data' field to the given value, the 'next' pointer to NULL, and returns the new node.
