Q LL
Q LL
h>
#include<conio.h>
struct Node
{
int data;
struct Node *next;
}*front = NULL,*rear = NULL;
void enq(int);
void deq();
void display();
void main()
{
int choice,data;
while(1)
{
printf("1. Enq\n2. Deq\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the value to be insert: ");
scanf("%d", &data);
enq(data);
break;
case 2:
deq();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Wrong choice\n");
}
}
}
void enq(int data)
{
struct Node *ptr;
ptr = (struct Node*)malloc(sizeof(struct Node));
ptr->data=data;
ptr->next=NULL;
if(front==NULL)
front=rear=ptr;
else
{
rear->next=ptr;
rear=ptr;
}
}
void deq()
{
if(front==NULL)
printf("Queue is Empty\n");
else
{
struct Node *ptr=front;
front=front->next;
printf("Deleted element %d\n", ptr->data);
free(ptr);
}
}
void display()
{
if(front==NULL)
printf("Queue is Empty\n");
else
{
struct Node *ptr = front;
while(ptr->next!=NULL)
{
printf("%d ",ptr->data);
ptr=ptr->next;
}
printf("%d \n",ptr->data);
}
}