//Static Implementation of Queue
#include <stdio.h>
#define MAX 50
typedef struct
{
int data[MAX];
int front, rear;
}QUEUE;
void initQ(QUEUE *pq)
{
pq->front = pq->rear = -1;
}
void addQ(QUEUE *pq, int num)
{
pq->rear++;
pq->data[pq->rear] = num;
}
int delQ(QUEUE *pq)
{
int num;
pq->front++;
num=pq->data[pq->front];
return (num);
}
int isempty(QUEUE *pq)
{
return(pq->front == pq->rear);
}
int isfull(QUEUE *pq)
{
return(pq->rear == MAX-1);
}
void main()
{
int n, choice;
QUEUE q1;
initQ(&q1);
printf(">>Static Implementation Of Queue<<");
do
{
printf("\n1.ADD \n");
printf("2.DELETE \n");
printf("3.EXIT \n");
printf("Enter Your Choice: \t");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter Element To Be Added:");
scanf("%d", &n);
if(isfull(&q1))
printf(">>Queue Overflow<<");
else
addQ(&q1, n);
break;
case 2:
if(isempty(&q1)==1)
printf(">>Queue Is Empty<<");
else
printf("The Deleted Element Is:%d \n", delQ(&q1));
break;
case 3:
printf("\t>>End <<\n");
break;
default:
printf("\n>>Enter Right Choice<<\n");
break;
}
}while(choice!=3);
}