while(head) // means while head is not equal to NULL
{
next=head;
head->next=temp;
temp=head;
head=next;
}
let us consider head is pointing to the current node
1. is the first node
now we have to do only change head->next=NULL
2.not the first node
now we have to assign head->next= // previous node so we have to keep track of the previous node so that assignment can be possible
that why we use the *temp to store previous node that can be assigned to head->next such that head->next=tmp
* for the first node temp is simply null
now initially if we assign head->next=temp then we cannot keep track of the current next node because my current next node link will be lost that's why it used *next to first store the link of the current next node and the update head->next=temp
after that the current node is stored in the temp and head is moved to the current next node