Swayam DSU Micro
Swayam DSU Micro
EDUCATION.
CERTIFICATE
This is to certify that
Mr./Mrs._________________________________________
Seal of Institution
1
INDEX
SR.NO. CONTENT
2 Algorithms
4 Output Of Program
5 Conclusion
2
WHAT IS A DATA STRUCTURE
A data structure is a specialized format of organizing and storing the data.
What is Queue ?
Queue is a linear data structure which follows First-In-First-Out(FIFO) principle where elements
are added at rear end and deleted from the first end.
3
ALGORITHMS
4
PROGRAM
Program to perform various operations on Circular Queue
#include<stdio.h>
#include<conio.h>
#include<string.h> #define max 3 int a[max],item,front=-
1,rear=-1; //initializing circular queue void insert(); void
delete(); void display(); void main()
{ int
choice;
char
ch='y';
clrscr();
printf("\n**********OPERATIONS ON CIRCULAR
QUEUE**********\n"); do {
printf("\n1:Insert\n");
printf("\n2:Delete\n");
printf("\n3:Display\n");
printf("\n4:Exit\n");
printf("\nEnter your choice:-
\n"); scanf("\n%d",&choice);
switch(choice)
{
case 1:insert();
break; case
2:delete();
break; case
3:display();
break; case
4:exit();
default:printf("\nYou entered wrong choice");
} printf("\nDo you want to continue(Y|N):-
\n"); scanf("%s",&ch);
}
while(ch=='y'||ch=='Y');
5
getch();
}
voidinsert()
{
if(front==rear+1)
{ printf("\nQueue is full!!!\n");
return;
}
else { printf("\nEnter the
element:-\n");
scanf("%d",&item); if(front==-
1) front=rear=0; else
rear=(rear+1)%max;
a[rear]=item;
}
printf("\n After insertion
Rear=%d\n",front,rear);
}
void
delete()
{
if(front==1)
{
printf("\nQueue is
empty!!!\n"); return;
} else { item=a[front];
printf("\nThe deleted element is:-
%d\n",item); if(front==rear) front=rear=-1;
else
front=(front+1)%max;
}
printf("\n After Deletion
Rear=%d\n",front,rear);
8
}
void
display() {
int i;
if(front==-1) { printf("\nQueue is
empty!!!\n"); return; } else {
printf("\nElement in Queue
are:\n"); for(i=front;i<=rear;i++)
printf("%d\t",a[i]); } if(front>rear)
{ for(i=front;i<max;i++)
printf("%d\t",a[i]);
for(i=0;i<=rear;i++)
printf("%d\t",a[i]);
}
return 0;
}
End of program
7
8
9
CONCLUSION:-
10