0% found this document useful (0 votes)
32 views7 pages

DSA Circular Queues

Consists of circular queues notes and code in c

Uploaded by

vedant.spamz65
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)
32 views7 pages

DSA Circular Queues

Consists of circular queues notes and code in c

Uploaded by

vedant.spamz65
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
You are on page 1/ 7

DATE

BR,
ASSiqnment

A to

Theoyi
A Queue FTFo (First-In,first- Out )

i n s e d irst iS the first


elenntS a q e e an addedo
e
the
omeY e n l the

UrU a thhe first indcx


man ofter the
aCo)

aci
f

The apenahon s.
(r1 Enqveue
oeavue
element S
en

onchor

te
PAGE NO

DATE

koDequee. frot

em
20
30

20

2)Dequr

Peauewe ORraSon s USe deett


The insced
dud
fst
onslhon onSild

is e p y As
f u r clus en wowd be

20 0

3)0iSpay:
tu ciseley

tt Timc corle

Enqueue

Daa
Ves. ef pCs Pnu and
USe ndtad UnderS Lol-
eo ahi obieev tollowing The
ConcuSion:
S21_100_VedantPatil

Code:
#include<stdio.h>
#include<conio.h>
struct queues
{
int arr[10];
int front;
int rear;
};
void enqueue();
void dequeue();
void display();
struct queues q1;
void main()
{
int n;
int choice;
q1.front=-1;
q1.rear=-1;
do
{
printf("1.AddElement\n2.RemoveElement\n3.Display\nEnter choice to be performed:
");
scanf("%d",&choice);
switch(choice)
{
case 1://Add elements
printf("Enter the number to be added: ");
scanf("%d",&n);
enqueue(n);
break;
case 2://Remove elements
dequeue();
break;
case 3://Display elements
display();
break;
default:
printf("Invalid choice");
break;
}
}while(choice<4);

void enqueue(int x)
S21_100_VedantPatil

{
if ((q1.rear + 1) % 10 == q1.front)
{
printf("Queue is full");
return;
}
else
{
if (q1.front == -1 && q1.rear == -1)
{
q1.front = 0;
q1.rear = 0;
}
else
{
q1.rear = (q1.rear + 1) % 10;
}
q1.arr[q1.rear] = x;
}
}

void dequeue()
{
if (q1.front == -1 && q1.rear == -1)
{
printf("Queue is empty\n");
return;
}
else
{
printf("%d is the element dequeued from the queue\n", q1.arr[q1.front]);
if (q1.front == q1.rear)
{
q1.front = -1;
q1.rear = -1;
}
else
{
q1.front = (q1.front + 1) % 10;
}
}
}
void display()
{
for(int i=q1.front;i<=q1.rear;i++)
{
printf("%d ",q1.arr[i]);
S21_100_VedantPatil

}
printf("\n");
}

Output:
1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 1

Enter the number to be added: 12

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 1

Enter the number to be added: 15

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 1

Enter the number to be added: 16

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 1

Enter the number to be added: 18

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 2

12 is the element dequeued from the queue

1.AddElement

2.RemoveElement
S21_100_VedantPatil

3.Display

Enter choice to be performed: 2

15 is the element dequeued from the queue

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 3

16 18

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 2

16 is the element dequeued from the queue

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 2

18 is the element dequeued from the queue

1.AddElement

2.RemoveElement

3.Display

Enter choice to be performed: 2

Queue is empty

You might also like