Doubt in self loop

can you please explain what happens when we insert the first node , and why do we have to point it to itself for the first node.
also i am getting wrong output

Hey @chitranshanmol07, i am not getting what do you mean by first node? Do you mean what will happen when we insert a new node at head?

The questions you have commented in your code are:
why not null?because last node points to head
Answer for that is , since your last element has it’s tail pointing to head of linked list which has an address instead of null value. So it will be head only. Moreover the code you wrote is working absolutely fine on IDE . So, there’s some technical issue in ide. Hope i helped you :smile: Keep learning :+1:

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.