Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the struct for a doubly linked list node.
DSA C
typedef struct Node {
int data;
struct Node* prev;
struct Node* [1];
} Node; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'previous' instead of 'next' for the forward pointer.
Using unrelated names like 'link' or 'child'.
✗ Incorrect
The 'next' pointer is used to point to the next node in a doubly linked list.
2fill in blank
mediumComplete the code to allocate memory for a new node.
DSA C
Node* newNode = (Node*) malloc(sizeof([1])); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'struct Node' when typedef is already used.
Using lowercase 'node' which is undefined.
✗ Incorrect
We use 'Node' as the type name to allocate memory for the struct.
3fill in blank
hardFix the error in the code to initialize the new node's pointers to NULL.
DSA C
newNode->prev = [1];
newNode->next = NULL; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullptr' which is C++ keyword.
Using 'nil' which is not valid in C.
✗ Incorrect
In C, NULL is used to represent a null pointer.
4fill in blank
hardFill both blanks to assign data and initialize pointers in the new node.
DSA C
newNode->data = [1]; newNode->prev = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'data' variable which may not exist.
Using 0 instead of NULL for pointers.
✗ Incorrect
Assign the input 'value' to data and set prev pointer to NULL.
5fill in blank
hardFill all three blanks to create a function that initializes a new doubly linked list node.
DSA C
Node* createNode(int [1]) { Node* newNode = (Node*) malloc(sizeof([2])); if (newNode != NULL) { newNode->data = [3]; newNode->prev = NULL; newNode->next = NULL; } return newNode; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Using 'struct Node' in malloc when typedef is used.
✗ Incorrect
The function takes 'value' as parameter, allocates memory for 'Node', and assigns 'value' to data.
