Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a node structure for a circular singly linked list.
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 'child' or 'link' which are not standard names here.
✗ Incorrect
The pointer to the next node in a singly linked list is commonly named 'next'.
2fill in blank
mediumComplete the code to create a new node and assign data to it.
DSA C
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or 0 instead of the actual data.
Using an undefined variable like 'value'.
✗ Incorrect
We assign the input 'data' value to the new node's data field.
3fill in blank
hardFix the error in linking the new node to itself for a single-node circular list.
DSA C
newNode->next = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to NULL breaks the circular property.
Using 'head' or 'temp' without initialization.
✗ Incorrect
For a single-node circular list, the node's next pointer should point to itself.
4fill in blank
hardFill both blanks to insert a new node at the end of a circular singly linked list.
DSA C
temp = head; while (temp->[1] != head) { temp = temp->[2]; } temp->next = newNode; newNode->next = head;
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 different pointer names in the loop causing errors.
✗ Incorrect
To traverse the circular list, we follow the 'next' pointers until we reach the head again.
5fill in blank
hardFill all three blanks to create a function that inserts a node at the end of a circular singly linked list.
DSA C
void insertEnd(struct Node** head, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = [1];
if (*head == NULL) {
newNode->next = [2];
*head = newNode;
} else {
struct Node* temp = *head;
while (temp->next != *head) {
temp = temp->next;
}
temp->next = newNode;
newNode->next = [3];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting newNode->next correctly for empty list.
Linking newNode->next to NULL instead of head.
✗ Incorrect
We assign 'data' to newNode->data, point newNode->next to itself if list is empty, and link newNode->next to head otherwise.
