0% found this document useful (0 votes)
12 views2 pages

Circular Queue Implementation in C

The document is a C program implementing a circular queue with basic operations such as insertion, deletion, and display. It defines functions to insert an element at the rear, delete an element from the front, and display the contents of the queue. The program continuously prompts the user for actions until they choose to exit.

Uploaded by

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

Circular Queue Implementation in C

The document is a C program implementing a circular queue with basic operations such as insertion, deletion, and display. It defines functions to insert an element at the rear, delete an element from the front, and display the contents of the queue. The program continuously prompts the user for actions until they choose to exit.

Uploaded by

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

#include<stdio.

h>
#define Q_size 5
void insertrear(int item,int q[],int r,int count);
void display(int count) ;
void deletefront(int q[] ,int f ,int count);
int choice,item,f=0,r=-1,q[5];
int count=0;
void main()
{

clrscr();

while(1)
{
printf("\n\t1--insert\n");
printf("\t2--delete\n");
printf("\t3--display\n");
printf("\t4--exit\n");
printf("\tenter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("enter the element\n");
scanf("%d",&item);
insertrear(item,q,r,count);
break;
case 2:
deletefront(q,f,count);
break;
case 3:
display(count);
break;
case 4:
exit();
}
}
}
void insertrear(int item,int q[5],int r,int count)
{ int i;
if (count == Q_size)
{
printf("Q IS FULL");
return;
}

printf("fist entry");
count=count+1;
printf("count :=%d",count);
r=(r+1)%Q_size;
q[r]=item;
printf("\nelement is inserted");
for (i=0;i<r;i++)
printf("%d",q[i]);

}
void deletefront(int q[] ,int f ,int count)
{
if(count==0)
{
printf("Q IS EMPTY");
return;
}
printf("deleted element is %d",q[f]);
f=(f+1)%Q_size;
count=count-1;
}
void display(int count)
{
int i;
if (count==0)
printf("Q is empty");
else
printf("contents of Q are");
for(i=0;i<count;i++)
{
printf("%d",q[f]);
f=(f+1)%Q_size;
}
}

You might also like