0% found this document useful (0 votes)
2 views4 pages

Queue Using Linked List

The document contains a C program that implements a queue using linked lists with operations for enqueue, dequeue, and display. It includes a menu for user interaction to perform these operations and displays the current state of the queue after each operation. The program has some incomplete sections and lacks proper error handling for certain cases.

Uploaded by

gsuriya2431
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Queue Using Linked List

The document contains a C program that implements a queue using linked lists with operations for enqueue, dequeue, and display. It includes a menu for user interaction to perform these operations and displays the current state of the queue after each operation. The program has some incomplete sections and lacks proper error handling for certain cases.

Uploaded by

gsuriya2431
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<stdio.

h>
#include<conio.h>
void inq();
void deq();
void display();
struct node // CREATING A NODE
{
int data;
struct node *link;
}*front=NULL,*rear=NULL;
int item;
void main()
{
int n;
clrscr();
printf("\tMENU\[Link]\[Link]\[Link]\[Link]\n");
do
{
printf("\nEnter your choice\n");
scanf("%d",&n);
switch(n)
{
case 1:
inq();
display();
break;
case 2:
deq();
display();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Invalid choice\n");
break;
}
}
while(n<=4);
getch();
}
void inq() // PERFORMING ENQUEUE OPERATION
{
struct node *temp;
printf("Enter the item\n");
scanf("%d",&item);
temp=(struct node*)malloc(sizeof(struct node));
temp->data=item;
temp->link=NULL;
if(rear==NULL)
{
}
else
{
}
}
front=temp;
rear=temp;
rear->link=temp;
rear=temp;
void deq() // PERFORMING DEQUEUE OPERATION
{
int item;
if(front==NULL)
{
}
else
{
}
printf("Queue is empty\n");
item=front->data;
printf("The element deleted = %d\n",item);
if(front==rear)
{
}
else
{
}
}
front=NULL;
rear=NULL;
front=front->link;
void display() // PERFORMING DISPLAY OPERATION
{
struct node *ptr;
if(front==NULL)
{
}
else
{
printf("Queue is empty\n");
ptr=front;
printf("The elements of the queue are :\n");
while(ptr!=NULL)
{
printf("%d\t",ptr->data);
ptr=ptr->link
}
}
}
Output:

OUTPUT:
MENU
[Link]
[Link]
[Link]
[Link]
Enter your choice:
1
Enter the item:
20
The elements of the queue are:
20
Enter your choice:
1
Enter the item:
30
The elements of the queue are:
20
30
Enter your choice:

You might also like