Lab Program No. 7
Lab Program No. 7
Create doubly linked list of N nodes with integer data by adding each node at the front.
Delete the node of a given data if it is found, otherwise display appropriate message.
Insert a node to the left of the node whose key value is read as input.
Display the contents of the list.
*/
#include <stdio.h>
#include <stdlib.h>
// Function to insert a node to the left of the node with a given key value
void insertNodeToLeft(struct Node** head, int key, int newData) {
if (*head == NULL) {
printf("List is empty.\n");
return;
}
if (temp->prev != NULL)
{
temp->prev->next = newNode;
}
else
{
*head = newNode; // New node is the new head
}
temp->prev = newNode;
printf("Node with data %d inserted before node with data %d.\n", newData, key);
return;
}
temp = temp->next;
}
printf("Node with key %d not found.\n", key);
}
return 0;
}