Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node for enqueue operation.
DSA C
struct Node* newNode = (struct Node*)malloc(sizeof([1])); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(int) instead of sizeof(Node).
Using sizeof(struct) which is invalid.
✗ Incorrect
We allocate memory for a new node, so we use sizeof(Node).
2fill in blank
mediumComplete the code to assign the data value to the new node.
DSA C
newNode->data = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning newNode->data = data (undefined variable).
Assigning newNode->data = NULL.
✗ Incorrect
We assign the input value to the data field of the new node.
3fill in blank
hardFix the error in linking the new node at the end of the queue.
DSA C
queue->rear->[1] = newNode; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next.
Assigning to data or rear fields.
✗ Incorrect
The next pointer of the rear node should point to the new node.
4fill in blank
hardFill both blanks to update the rear pointer and set the new node's next to NULL.
DSA C
queue->rear = [1]; newNode->[2] = NULL;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting rear to queue instead of newNode.
Setting newNode->prev to NULL instead of next.
✗ Incorrect
The rear pointer should point to the new node, and newNode's next should be NULL.
5fill in blank
hardFill all three blanks to handle the empty queue case and enqueue the new node correctly.
DSA C
if (queue->rear == NULL) { queue->front = [1]; queue->rear = [2]; } else { queue->rear->next = [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning rear or front to queue instead of newNode.
Assigning rear->next to NULL instead of newNode.
✗ Incorrect
When the queue is empty, both front and rear point to newNode. Otherwise, link newNode after rear.
