#include #include typedef struct node { int data; struct node *prev; struct node *next; } NODE; NODE *head = NULL; void insert_front(int value) { NODE *newNode = (NODE *)malloc(sizeof(NODE)); if (newNode == NULL) { printf("Memory allocation failed\n"); return; } newNode->data = value; newNode->prev = NULL; newNode->next = head; if (head != NULL) { head->prev = newNode; } head = newNode; printf("Inserted %d\n", value); } void delete_value(int value) { NODE *temp = head; if (head == NULL) { printf("List is empty\n"); return; } while (temp != NULL) { if (temp->data == value) { if (temp->prev == NULL) { head = temp->next; if (head != NULL) head->prev = NULL; } else { temp->prev->next = temp->next; if (temp->next != NULL) temp->next->prev = temp->prev; } free(temp); printf("Deleted %d\n", value); return; } temp = temp->next; } printf("Value not found\n"); } void display() { NODE *temp = head; if (head == NULL) { printf("List is empty\n"); return; } printf("List: "); while (temp != NULL) { printf("%d <-> ", temp->data); temp = temp->next; } printf("NULL\n"); } int main() { int choice, value; while (1) { printf("\n--- DOUBLY LINKED LIST MENU ---\n"); printf("1. Insert at front\n"); printf("2. Delete by value\n"); printf("3. Display\n"); printf("4. Exit\n"); printf("Enter choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Enter value to insert: "); scanf("%d", &value); insert_front(value); break; case 2: printf("Enter value to delete: "); scanf("%d", &value); delete_value(value); break; case 3: display(); break; case 4: printf("Exiting...\n"); exit(0); default: printf("Invalid choice\n"); } } }