Queue Linked List
Queue Linked List
//header files
#include <stdio.h>
#include <stdlib.h>
// Declare global pointers for the front and rear of the queue.
struct node *front;
struct node *rear;
// Function prototypes.
void insert();
void delete();
void display();
switch (choice)
{
case 1:
insert();//insertion
break;
case 2:
delete();//deletion
break;
case 3:
display();//dispay queue
break;
case 4:
exit(0);
break;
default://default case
printf("Enter a valid choice.\n");
}
}
return 0;
}
// Function to insert an element into the queue.
void insert()
{
struct node *ptr;
int item;
ptr->data = item;
if (front == NULL)
{
// If the queue is empty, set both front and rear to the new node.
front = ptr;
rear = ptr;
front->next = NULL;
rear->next = NULL;
}
else
{
// If the queue is not empty, add the new node to the rear.
rear->next = ptr;
rear = ptr;
rear->next = NULL;
}
}
}