Linked list insertion

what is difference in while(temp!=null) and while(temp->next!=null) in insertion at end.
i mean what if we replace them.
please explain with example.

hello @khushiujjawal
consider this list.

1-> 2 -> NULL

for this case , we will go inside the loop for node 1 and node 2 becuase they are not null.

for this , we will go inisde loop only for 1 and not for 2. becuase 2’s next contains null so loop will stop there only

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.