8
8
h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
while (1) {
printf("\nMenu:\n");
printf("1. Insert at position\n");
printf("2. Display linked list\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter data to insert: ");
scanf("%d", &data);
printf("Enter position to insert at: ");
scanf("%d", &position);
insertAtPosition(&head, data, position);
break;
case 2:
printf("Linked List:\n");
display(head);
break;
case 3:
freeList(head);
printf("Exiting program.\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
}