After you follow the instructions below
Node* runner = head->next;
'runner' points to the address memory indicated by "next" (for example, this is address 0x6543).
(head-> next) ------> content <---- (runner)
The following two lines:
Node* reversedList = head; reversedList->next = nullptr;
So, "next" now points to NULL, but "runner" still points to the address previously indicated by "next", that is, 0x6543.
(head-> next) → NULL | content <-------- (runner)
The second example works because first you make head-> next points equal to NULL, then you make "runner" points to head-> next, now it is NULL. Like the "head" and the "reverseedList", both points to the same address, the second example - without reverseedList - would be:
head->next = nullptr; Node* runner = head->next;
source share