Is this code is correct for DDL insertion at head?

void insertAtHead(node *&head, int d)
{
if (head == NULL)
{
head = new node(d);
}
else
{
node *temp = new node(d);
temp->next = head;
head->prev = temp;
temp ->prev = NULL;
head = temp;
}
}

Hello @amit0001 yes this is correct.
I think just you can add one think more is when he list is empty then also you can add head->prev =NULL

okay____________________________________________________

@amit0001 if you feel that your doubt is resolved you can mark it as resolved.
Happy Learning!!

I think there is a problem with the site bcoz I already mark as resolve many times, I will do again

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.