50% found this document useful (2 votes)
4K views

Data Structure Prac. No. 5 Write A Program To Insert, Delete, Display The Elements of A Queue

This program implements a queue using an array. It allows the user to insert elements into the queue, delete elements from the queue, and display all elements of the queue. The functions pq() inserts elements, nq() deletes elements, and display() prints all elements currently in the queue. The main() function uses a do-while loop to repeatedly call these functions based on user input until the user chooses to exit.

Uploaded by

YOGESH MUNEJA
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
4K views

Data Structure Prac. No. 5 Write A Program To Insert, Delete, Display The Elements of A Queue

This program implements a queue using an array. It allows the user to insert elements into the queue, delete elements from the queue, and display all elements of the queue. The functions pq() inserts elements, nq() deletes elements, and display() prints all elements currently in the queue. The main() function uses a do-while loop to repeatedly call these functions based on user input until the user chooses to exit.

Uploaded by

YOGESH MUNEJA
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM-5

AIM:-WRITE A PROGRAM TO INSERT, DELETE, DISPLAY THE


ELEMENTS OF A QUEUE
#include<conio.h>
#include<stdio.h>
#define size 100
int a[size];
int front=-1,rear=-1;
void nq();
void pq();
void display();
void main()
{
int num;
do
{
printf("\nenter 1 to insert,2 to delete,3 to display the elements");
scanf("%d",&num);
switch(num)
{
case 1:
pq();
break;
case 2:
nq();
break;
case 3:
display();
}
printf("\nenter 1 for applying loop again,2 to exit");
scanf("%d",&num);
}while(num==1);
}
void pq()
{
int item;
if(rear==size-1)
{
printf("\nqueue overflow");
return;
}
printf("\nenter the element");
scanf("%d",&item);
if(rear==-1)
rear=front=0;
else
rear++;
a[rear]=item;
}
void nq()
{
if(front==-1)
{
printf("\nqueue is empty");
return;
}
printf("\nelement deleted is %d",a[front]);
if(front==rear)
front=rear=-1;
else
front++;
}
void display()
{
int i;
for(i=front;i<=rear;i++)
printf("\n%dth element=%d",i+1,a[i]);
}
OUTPUT:-

You might also like