#include<stdio.h>
#include<conio.h>
#define boundary 5
struct queue
{
int item[boundary];
int front,rear;
};
struct queue q;
void insertion();
void display();
void delet();
int main ()
{
int ch=0;
q.front=boundary-1;
q.rear=boundary-1;
clrscr();
while(ch!=4)
{
printf("\n1. Insertion\n2. Deletion\n3. Display\n4. Exit\n\n");
scanf("%d",&ch);
switch(ch)
{
case 1: insertion();
break;
case 2: delet();
break;
case 3: display();
break;
default : printf("\nPlease enter the right choise!\n");
}
}
return 0;
}
void insertion()
{
int e;
if((q.rear+1)%boundary==q.front)
printf("No space!\n");
else
{
printf("Enter the element: ");
scanf("%d",&e);
q.rear=(q.rear+1)%boundary;
q.item[q.rear]=e;
printf("Rear position->%d\n",q.rear);
printf("Front position->%d\n",q.front);
}
}
void display()
{
int i;
if(q.rear==q.front)
printf("No data in CIRCULAR queue!\n");
else
{
printf("\nThe elements are: ");
if(q.front!=4)
{
for(i=q.front+1;i<=q.rear;i++)
printf("%d ",q.item[i]);
}
else
{
for(i=0;i<=q.rear;i++)
printf("%d ",q.item[i]);
}
printf("\n");
}
}
void delet()
{
if(q.rear==q.front)
printf("No data in CIRCULAR queue!\n");
else
q.front=(q.front+1)%boundary;
printf("Rear position->%d\n",q.rear);
printf("Front position->%d\n",q.front);
}
Related posts: