#include #include struct node { int data; struct node* prev; struct node* next; }; struct node* head = NULL; void input(int); void traverseForward(); void traverseBackward(); int main() { int n; printf("Enter the number of nodes: "); scanf("%d", &n); input(n); traverseForward(); traverseBackward(); return 0; } void input(int n) { int d; struct node *temp = NULL; struct node *newnode = NULL; for (int i = 1; i <= n; i++) { newnode = (struct node*)malloc(sizeof(struct node)); if (newnode == NULL) { printf("Memory allocation failed"); return; } printf("Enter the value for node %d: ", i); scanf("%d", &d); newnode->data = d; newnode->prev = NULL; newnode->next = NULL; if (head == NULL) { head = newnode; temp = head; } else { temp->next = newnode; newnode->prev = temp; temp = newnode; } } } void traverseForward() { struct node *temp = head; printf("\nForward traversal:\n"); while (temp != NULL) { printf("%d \t", temp->data); temp = temp->next; } printf("\n"); } void traverseBackward() { struct node *temp = head; if (temp == NULL) { printf("Doubly linked list is empty.\n"); return; } while (temp->next != NULL) { temp = temp->next; } printf("Backward traversal:\n"); while (temp != NULL) { printf("%d \t", temp->data); temp = temp->prev; } printf("\n"); }