#include<stdio.h>
#include<stdlib.h>
#define queuesize 4
int q[queuesize];
void enqueue(int );
void dequeue();
void display();
int r=-1;
int f=0;
int count=0;
int main()
{
int ch,item;
printf("\n");
while(1)
{
scanf("%d",&ch);
switch(ch)
{
case 1 : scanf("%d",&item);
enqueue(item);break;
case 2 : dequeue();break;
case 3 : display();break;
case 4 : exit(0);
default: printf("Invalid Choice\n");
}
}
return 0;
}
void enqueue(int item)
{
if(count==queuesize)
{
printf("Circular Queue overflow cannot enqueue\n");
return;
}
r=(r+1)%queuesize;
q[r]=item;
count=count+1;
}
void dequeue()
{
if(count==0)
{
printf("Circular Queue Underflow cannot dequeue\n");
return;
}
printf("Dequeued element is:%d\n",q[f]);
f=((f+1)%queuesize);
count=count-1;
}
void display()
{
if(count==0)
{
printf("Circular Queue is empty nothing to display\n");
return;
}
for(int i=0;i<count;i++)
{
printf("%d ",q[(f+i)%queuesize]);
// f=(f+i)%queuesize;
}
printf("\n");
}
To embed this project on your website, copy the following code and paste it into your website's HTML: