Linking The Lists

Statement 1 : n->next = head;
What does this statement do? Point to the next of head? Or point to head?

Statement 2 : head = n;
What does this statement do? Point to n?

I am unable to understand the difference between the two statements and their usage.

Lets say we have a linked list with a given head pointer and a node n.
We have to insert the node n in the beginning of our linked list.
n->next = head makes the given node’s next pointer point to the head of our linked list.
Now the head our new linked list is the node n. So we update the head of our linked list by “head = n” statement.

1 Like

@poojagera Please mark your doubt as resolved if you are satisfied.

1 Like

Hi! My doubt is resolved but I am unable to mark it resolved. There is some problem with the website I think.

Oh Okay no problem. Try doing it later maybe.

@poojagera Try marking your doubt as resolved now.

Still not happening 🥺 I am able to mark every other doubt resolved I have no idea what’s specifically wrong with this one.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like