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

Circular

Uploaded by

Tanvi Shinde
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)
1 views7 pages

Circular

Uploaded by

Tanvi Shinde
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

Name: Saheranjum M.

Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Q1. Write a program to using Circular Queue.


#include<stdio.h>
#define size 5
int cq[size],front=-1,rear=-1;
int qfull()
{
if(front==(rear+1)%size)
return 1;
else
return 0;
}
int qempty()
{
if(front==-1)
return 1;
else
return 0;
}
void insert(int item)
{
if(qfull())
printf("q is full");
else
{
if(front==-1)
front=rear=0;
else
rear=(rear+1)%size;
cq[rear]=item;
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

}
}

int del()
{
int item;
if(qempty())
printf("q is empty");
else
{
item=cq[front];
if(front==rear)
{
front=rear=-1;
}
else
front=(front+1)%size;
}
return item;
}
void display()
{
int i;
if(qempty())
printf("q is empty");

for(i=front;i!=rear;)
{
printf("%d\t",cq[i]);
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

i=(i+1)%size;
}
printf("%d",cq[i]);
}
int main()
{
int item,choice;
clrscr();
printf("\nCIRCULAR QUEUE\n");
do
{
printf("\n Enter your choice: \n 1 Add \n 2 Del\n 3 Display\n 4 Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\n Enter element to add\n");
scanf("%d",&item);
if(qfull())
printf("\n q is full");
else
insert(item);
break;
}
case 2:
{
if(qempty())
printf("\n q is empty");
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

else
{
item=del();
printf("\n delete element is %d",item);
}
break;
}
case 3:
{
display();
break;
}
case 4:
printf("\n Exit");
break;
}
}
while(choice!=4);
return 0;
}

OUTPUT:
Queue is empty
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Adding elements:
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Queue is full:

Display elements:
Name: Saheranjum M. Makandar
Roll No: 72
Class: B-Tech SY DS
Batch: C4

Delete an element:

You might also like