hello every one i hope you doing will
so my problem is there
check the code and help me
Code:
#include<stdio.h>
#include<conio.h>
#define max 5
struct queue
{
int front,rear,q[max];
};
void enqueue(struct queue*);
void dequeue(struct queue*);
void qdisplay(struct queue*);
void main(void)
{
int c;
struct queue q;
q.front=q.rear=-1;
do
{
printf("1:insert\n2:deletion\n3:display\n4:exit\nenter choice:");
scanf("%d",&c);
switch(c)
{
case 1:enqueue(&q);break;
case 2:dequeue(&q);break;
case 3:qdisplay(&q);break;
case 4:printf("pgm ends\n");break;
default:printf("wrong choice\n");break;
}
}while(c!=4);
getch();
}
void enqueue(struct queue *p1)
{
int x;
if((p1->front==0&&p1->rear==max-1)||(p1->front==p1->rear+1))
C program to implement circular Queue using Structure {
printf("q is overflow\n");return;
}
if(p1->front==-1)
{
p1->front=p1->rear=0;
}
else
{
if(p1->rear==max-1)
{
p1->rear=0;
}
else
{
p1->rear++;
}
}
printf("enter the no:\n");
scanf("%d",&x);
p1->q[p1->rear]=x;
printf("%d succ. inserted\n",x);
return;
}
void dequeue(struct queue *p2)
{
int y;
if(p2->front==-1)
{
printf("q is underflow\n");return;
}
y=p2->q[p2->front];
if(p2->front==p2->rear)
{
p2->front=p2->rear=-1;
}
else
{
if(p2->front==max-1)
{
p2->front=0;
}
else
{
p2->front++;
}
}
printf("%d succ. deleted\n",y);
return;
}
void qdisplay(struct queue *p3)
{
int i,j;
if(p3->front==p3->rear==-1)
{
printf("q is empty\n");return;
}
printf("elements are :\n");
for(i=p3->front;i!=p3->rear;i=(i+1)%max)
{
printf("%d\n",p3->q[i]);
}
printf("%d\n",p3->q[p3->rear]);
return;
}