#include<conio.h>
#include<stdio.h>
#define max 6
struct qtype{int front;int rear;int ele[max];};

int iscqempty(struct qtype q)
{
 return(q.rear==q.front);
}

int iscqfull(struct qtype q)
{
 if(q.rear==max-1) q.rear=0;
 else q.rear++;
 return(q.rear==q.front);
}

void makeempty(struct qtype *q)
{
 q->rear=q->front=0;
 printf("QUEUE IS MADE EMPTY:");
}

void addcq(struct qtype *q,int x)
{
 if(q->rear==max-1) q->rear=0;
 else q->rear++;
 q->ele[q->rear]=x;
}

int delcq(struct qtype *q)
{
 if(q->front==max-1)
 q->front=0;
 else
 return(q->ele[1+q->front++]);
}

void dispcq(struct qtype q)
{
 int i;
 if(q.rear>q.front)
  for(i=q.front+1;i<=q.rear;i++)  printf("%d\t",q.ele[i]);
 else
 {
  for(i=q.front+1;i<max;i++) printf("%d\t",q.ele[i]);
  for(i=0;i<=q.rear;i++)     printf("%d\t",q.ele[i]);
 }
}

void main()
{
 struct qtype q={0,0,{0}};
 int n,x;
 while(1)
 {
  clrscr();
  printf("1.ADD\n 2.DELETE\n 3.LIST\n 4.MAKE-EMPTY\n 5.EXIT\n");
  printf("ENTER UR CHOICE 1/2/3/4/5\n");
  scanf("%d",&n);
  if(n==5) break;
  switch(n)
  {
   case 1:
	  if(!iscqfull(q))
	  {
	   printf("ENTER THE NUMBER TO BE ADDED:");
	   scanf("%d",&x);
	   addcq(&q,x);
	  }
	  else printf("QUEUE IS OVERFLOW:");
	  break;
   case 2:
	  if(iscqempty(q))
	   printf("\n UNDERFLOW");
	  else printf("DELETED ELEMENT IS %d",delcq(&q));
	  break;
   case 3:
	  if(iscqempty(q))    printf("\n UNDERFLOW");
	  else   dispcq(q);
	  break;
   case 4:
	  makeempty(&q);
	  break;
   default: printf("\nINVALID OPTION");
  }
   getch();
 }
 getch();
}
