How come the ordering of the marked code plays a vital role ,and why does it show error when we write these steps in different order that is when i write temp->next = n; before than n->next;

hello @sauravzt7

if u will first do this->
temp->next=n
then u will lost the address of temp->next (node next to inserted node).

that is why ordering matters here.
first we are doing
n=temp->next; (connecting newly inserted node to the next node)
and then
temp->next=n; (connecting previous node to newly inserted node)

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.