Doubly linked list

what is wrong in this delete function for a doubly linked list

@ayu2321, you did’nt handle the case where node to be deleted is the head of the linked list, also i don;t understand why you are returning NULL

now also it is giving error
Node* deleteNode(Node *head, int x) {
// Write your code here
Node *temp = head;

if(head == NULL){
    return NULL;
}
if(head->data == NULL){
    if(head->next == NULL){
        delete head;
    }
    else{
        head = head->next;
    }
}
while(temp->next!=NULL){
    if(temp->data == x){
        temp->prev->next = temp->next;
    }
    else{
        return NULL;
    }
    temp = temp->next;
}
return head;

}

i have written head-> data == x in previous code

instead of
if(head->data == NULL) it should be if(head->data == x)
also after deleting from head you have to return head immediately or else while loop will be executed

send me the question link so i can check properly, i have to see if node values are unique or not , and if we have to delete all nodes with value x or single node

@ayu2321, there seems to be some issue with the checker


i have checked with other case this works fine, also their editorial solution is not passing either

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.