Complete the code to move to the last node in the linked list.
while (temp->next [1] nullptr) { temp = temp->next; }
We use '!=' to continue moving until the next node is nullptr, which means the end of the list.
Complete the code to delete the last node safely.
Node* toDelete = temp->next;
temp->next = [1];
delete toDelete;We set temp->next to nullptr to remove the last node from the list before deleting it.
Fix the error in the code to handle deleting the last node when the list has only one node.
if (head->next == [1]) { delete head; head = nullptr; }
If the head's next is nullptr, it means only one node exists. We delete it and set head to nullptr.
Fill both blanks to traverse to the second last node before deletion.
Node* temp = head; while (temp->[1]->[2] != nullptr) { temp = temp->next; }
We move temp while temp->next->next is not nullptr to stop at the second last node.
Fill all three blanks to delete the last node and update the list correctly.
Node* temp = head; while (temp->[1]->[2] != nullptr) { temp = temp->next; } Node* toDelete = temp->[3]; temp->next = nullptr; delete toDelete;
We use temp->next->next to find the second last node, then delete temp->next.
