Complete the code to update the head pointer to the next node after deletion.
head = [1];After deleting the first node, the head should point to the next node in the list.
Complete the code to free the memory of the deleted node.
struct Node* temp = head;
head = head->next;
[1](temp);In C, free() is used to release memory allocated with malloc().
Fix the error in the condition to check if the list is empty before deletion.
if ([1] == NULL) { printf("List is empty\n"); return; }
To check if the list is empty, we check if the head pointer itself is NULL.
Fill both blanks to correctly delete the first node and update the head.
if (head == NULL) { printf("List is empty\n"); return; } struct Node* [1] = head; head = [2]; free(temp);
We store the current head in temp, then move head to the next node before freeing temp.
Fill all three blanks to implement a function that deletes the first node of a singly linked list.
void deleteAtBeginning(struct Node** [1]) { if (*[1] == NULL) { printf("List is empty\n"); return; } struct Node* temp = *[1]; *[2] = (*[3])->next; free(temp); }
The function takes a pointer to the head pointer. We check if the list is empty by dereferencing *head. Then we update *head to point to the next node before freeing the old head.
