void deleteAllOccurOfX(struct Node** head, int x) {
if (*head == NULL)
return;
// Handle the case where the value to delete is at the beginning of the list
while (*head != NULL && (*head)->data == x) {
struct Node* temp = *head;
*head = (*head)->next;
delete temp;
}
struct Node* p = *head;
while (p != NULL) {
struct Node* nn = p->next;
if (p->data == x) {
p->prev->next = nn;
// If the node to delete is at the end of the list
if (nn != NULL)
nn->prev = p->prev;
delete p;
}
p = nn;
}
}