I have a small code snippet for deleting element in linked list. Here is the code:
if (head->data == num) {
delete head;
head = head->next;
}
Can you please explain to me, why this code works. It deletes the head and sets the head to the next element.
When I saw this I thought that this will not work but it works.