struct Queue
{
int Data;
struct Queue* next;
}*rear, *front;
void enqueue (int value)
{
if (rear == NULL)
{
rear = (struct Queue *) malloc(sizeof(struct Queue));
rear->next = NULL;
rear->Data = value;
front = rear;
}
else
{
temp = (struct Queue *)malloc(sizeof(struct Queue));
rear->next = temp;
temp->Data = data;
temp->next = NULL;
rear = temp;
}
}
void dequeue()
{
front1 = front;
if (front1 == NULL)
{
printf(" Error: Trying to display elements from empty queue");
return;
}
else
if (front1->next != NULL)
{
printf("Dequed value : %d", front1->Data);
front1 = front1->next;
free(front);
front = front1;
}
else
{
printf("Dequed value : %d", front->Data);
free(front);
front = NULL;
rear = NULL;
}
}
void display()
{
struct Node *var = rear;
if(var == NULL)
printf("\nQueue is Empty");
else
{
while(var!=NULL)
{
printf("%d",var->Data);
var=var->next;
}
}
}