#include <stdio.
h>
#include <stdlib.h> // For malloc, exit()
struct node {
int label;
struct node *next;
};
int main() {
int ch = 0;
struct node *h, *temp, *head;
// Create a dummy head node
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
while (1) {
printf("\nQueue using Linked List\n");
printf("1 -> Insert\n");
printf("2 -> Delete\n");
printf("3 -> View\n");
printf("4 -> Exit\n");
printf("Enter your choice: ");
scanf("%d", &ch);
switch (ch) {
case 1: // Insert at rear
temp = (struct node *)malloc(sizeof(struct node));
if (!temp) {
printf("Memory allocation failed.\n");
break;
}
printf("Enter label for new node: ");
scanf("%d", &temp->label);
temp->next = NULL;
h = head;
while (h->next != NULL)
h = h->next;
h->next = temp;
printf("Node inserted.\n");
break;
case 2: // Delete from front
if (head->next == NULL) {
printf("Queue Underflow (Empty Queue)\n");
break;
}
h = head->next;
head->next = h->next;
printf("Node %d deleted\n", h->label);
free(h);
break;
case 3: // View queue
printf("\nHEAD -> ");
h = head->next;
while (h != NULL) {
printf("%d -> ", h->label);
h = h->next;
}
printf("NULL\n");
break;
case 4: // Exit
printf("Exiting...\n");
exit(0);
default:
printf("Invalid choice. Try again.\n");
}
}
return 0;
}