#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 100
struct queue
{
int item[size];
int front,rear;
}q;
void insert(struct queue *pq,int x)
{
if(pq->rear==99)
pq->rear=0;
else
pq->rear++;
if(pq->rear==pq->front)
{
printf("\nQUEUE OVERFLOW");
}
else
pq->item[pq->rear]=x;
}
int remove1(struct queue *pq)
{
if(pq->rear==pq->front)
{
printf("\nQUEUE UNDERFLOW");
}
if(pq->front==99)
pq->front=0;
else
++(pq->front);
return(pq->item[pq->front]);
}
void display()
{
int k;
printf("\nOUTPUT==>>");
for(k=q.front+1;k<=q.rear;k++)
printf("\t%d",q.item[k]);
}
void main()
{
int i,j;
clrscr();
q.rear=99;
q.front=99;
while(1)
{
printf("\nPress 1 for enter=");
printf("\nPress 2 for remove=");
printf("\nPress 3 for display=");
printf("\nPress 4 for exit=");
printf("\nEnter Choice=");
scanf("%d",&i);
clrscr();
printf("\n\n\t\t\t\t<<==CIRCULAR QUEUE==>>\n\n");
switch(i)
{
case 1: printf("\nEnter element=");
scanf("%d",&j);
insert(&q,j);
break;
case 2: printf("\nThe remove element is=%d",remove1(&q));
break;
case 3: display();
break;
case 4: exit(0);
default:printf("\n\bWRONG CHOICE");
}
}
getch();
}
#include<conio.h>
#include<stdlib.h>
#define size 100
struct queue
{
int item[size];
int front,rear;
}q;
void insert(struct queue *pq,int x)
{
if(pq->rear==99)
pq->rear=0;
else
pq->rear++;
if(pq->rear==pq->front)
{
printf("\nQUEUE OVERFLOW");
}
else
pq->item[pq->rear]=x;
}
int remove1(struct queue *pq)
{
if(pq->rear==pq->front)
{
printf("\nQUEUE UNDERFLOW");
}
if(pq->front==99)
pq->front=0;
else
++(pq->front);
return(pq->item[pq->front]);
}
void display()
{
int k;
printf("\nOUTPUT==>>");
for(k=q.front+1;k<=q.rear;k++)
printf("\t%d",q.item[k]);
}
void main()
{
int i,j;
clrscr();
q.rear=99;
q.front=99;
while(1)
{
printf("\nPress 1 for enter=");
printf("\nPress 2 for remove=");
printf("\nPress 3 for display=");
printf("\nPress 4 for exit=");
printf("\nEnter Choice=");
scanf("%d",&i);
clrscr();
printf("\n\n\t\t\t\t<<==CIRCULAR QUEUE==>>\n\n");
switch(i)
{
case 1: printf("\nEnter element=");
scanf("%d",&j);
insert(&q,j);
break;
case 2: printf("\nThe remove element is=%d",remove1(&q));
break;
case 3: display();
break;
case 4: exit(0);
default:printf("\n\bWRONG CHOICE");
}
}
getch();
}
No comments:
Post a Comment