Initialize a pointer head to the linked list as NULL. Display the menu options to the user, which include: Add an element to the front Add an element to the end Delete an element from the front Delete an element from the end Delete a specific element Display the linked list Exit Prompt the user to enter a choice If the choice is 1: create a new node with data if (temp == NULL) Print memeory underflow else temp->data = value temp->linl = head head = temp If the choice is 2: set ptr = head while ptr->link != NULL ptr= ptr->link ptr->link = temp temp->data = item temp->link = Null If the choice is 3: if head == null print list is empty else head = head -> link If the choice is 4: set current = head, prev = head while (current -> link != NULL) prev = current current = current->link prev->link = NULL If the choice is 5: set ptr = head if ptr == null print empty else while(ptr != NULL) print ptr->data ptr = ptr->link If the choice is 6: exit the program -------------------------------------------------------------------------------------------------- #include #include struct Node* createNode(int data); void displayList(struct Node* head); void deleteEnd(struct Node** head); void deleteFront(struct Node** head); void addEnd(struct Node** head, int data); void addFront(struct Node** head, int data); void addAnywhere(struct Node** head, int data, int position); void deleteAnywhere(struct Node** head, int position); struct Node { int data; struct Node* next; }; int main() { struct Node* head = NULL; int choice, data,place; while (1) { printf("\nMenu:\n"); printf("1. Add an element to the front\n"); printf("2. Add an element to the end\n"); printf("3. Add an element anywhere\n"); printf("4. Delete an element from the front\n"); printf("5. Delete an element from the end\n"); printf("6. Delete an element from anywhere\n"); printf("7. Display the linked list\n"); printf("8. Exit\n\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Enter the data to add to the front: "); scanf("%d", &data); addFront(&head, data); break; case 2: printf("Enter the data to add to the end: "); scanf("%d", &data); addEnd(&head, data); break; case 3: printf("Enter the data to add anywhere: "); scanf("%d", &data); printf("Enter the index to add: "); scanf("%d", &place); addAnywhere(&head,data,place); break; case 4: deleteFront(&head); break; case 5: deleteEnd(&head); break; case 6: printf("Enter the index to delete: "); scanf("%d", &place); deleteAnywhere(&head,place); break; case 7: displayList(head); break; case 8: exit(0); default: printf("Invalid choice. Please try again.\n"); } } } struct Node* createNode(int data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); if (newNode == NULL) { printf("Memory allocation failed.\n"); exit(1); } newNode->data = data; newNode->next = NULL; return newNode; } void addFront(struct Node** head, int data) { struct Node* newNode = createNode(data); newNode->next = *head; *head = newNode; printf("\%d added to the front of the list.\n", data); } void addEnd(struct Node** head, int data) { struct Node* newNode = createNode(data); if (*head == NULL) { *head = newNode; } else { struct Node* current = *head; while (current->next != NULL) { current = current->next; } current->next = newNode; } printf("%d added to the end of the list.\n", data); } void deleteFront(struct Node** head) { if (*head == NULL) { printf("The list is empty.\n"); return; } struct Node* temp = *head; *head = (*head)->next; printf("%d deleted from the front of the list.\n", temp->data); free(temp); } void deleteEnd(struct Node** head) { if (*head == NULL) { printf("The list is empty.\n"); return; } if ((*head)->next == NULL) { printf("%d deleted from the list.\n", (*head)->data); free(*head); *head = NULL; return; } struct Node* current = *head; while (current->next->next != NULL) { current = current->next; } printf("%d deleted from the end of the list.\n", current->next->data); free(current->next); current->next = NULL; } void displayList(struct Node* head) { struct Node* current = head; printf("Linked List: "); while (current != NULL) { printf("%d -> ", current->data); current = current->next; } printf("NULL\n"); } void addAnywhere(struct Node** head, int data, int position) { struct Node* newNode = createNode(data); if (position == 1) { newNode->next = *head; *head = newNode; return; } struct Node* current = *head; int i; for (i = 1; i < position - 1 && current != NULL; i++) { current = current->next; } if (current == NULL) { printf("Invalid position. Node can't be added.\n"); } else { newNode->next = current->next; current->next = newNode; printf("%d added at position [%d].\n", data,position); } } void deleteAnywhere(struct Node** head, int position) { if (*head == NULL) { printf("List is empty. Node can't be deleted.\n"); return; } if (position == 1) { struct Node* temp = *head; *head = (*head)->next; free(temp); return; } struct Node* current = *head; struct Node* prev = NULL; int i; for (i = 1; i < position && current != NULL; i++) { prev = current; current = current->next; } if (current == NULL) { printf("Invalid position. Node can't be deleted.\n"); } else { prev->next = current->next; free(current); } }