#include #include struct node { int num; struct node *next; struct node *prev; }; struct node *first = NULL; struct node *last = NULL; struct node *temp = NULL; int main() { int ch=0; int tmp; while(ch != 4) { printf("Enter 1 to add a node\nEnter 2 to display the list in forward order \nEnter 3 to display the list in reverse order \nEnter 4 to exit \nEnter choice: "); scanf("%d",&ch); if(ch == 1) { if(first == NULL) { first = (struct node *)malloc(sizeof(struct node)); printf("Enter a number: "); scanf("%d",&tmp); first->num = tmp; first->next = NULL; first->prev = NULL; last = first; printf("Node created\n"); } else { temp = malloc(sizeof(struct node)); printf("Enter a number: "); scanf("%d",&tmp); temp->num = tmp; last->next = temp; temp->prev = last; last = last->next; printf("Node created\n"); } } else if(ch == 2) { if(first == NULL) { printf("List is empty\n"); } else { temp = first; while(temp != NULL) { printf("%d ",temp->num); temp = temp -> next; } printf("\n"); } } else if(ch == 3) { if(first == NULL) { printf("List is empty\n"); } else { temp = last; while(temp != NULL) { printf("%d ",temp->num); temp = temp -> prev; } printf("\n"); } } else if(ch == 4) { // exit(0); } } }