#include
#define MAX 3
struct que
{
int data[MAX];
int front,rear;
};
typedef struct que que;
int full(que q)
{
if(q.rear==MAX-1)
return(1);
else
return(0);
}
int empty(que q)
{
if(q.rear==-1)
return(1);
else
return(0);
}
int qinsert(que *q,int num)
{
if(full(*q))
{
printf("\n que full");
return(1);
}
q->rear++;
q->data[q->rear]=num;
}
int qdelete(que *q)
{
int num;
if(empty(*q))
{
printf("\nque is empty");
return(-1);
}
else
{
num=q->data[q->front];
if(q->front==q->rear)
{
q->front=0;
q->rear=-1;
}
else
q->front++;
}
return(num);
}
int qdisplay(que q)
{
int i;
if(empty(q))
{
printf("\n que is empty");
return(1);
}
printf("\n the contents ");
for(i=q.front;i<=q.rear;i++)
printf("%5d",q.data[i]);
}
int main()
{
int ch,i,num;
que q;
int done=0;
q.front=0;
q.rear=-1;
while(!done)
{
printf("\n 1.to insert que"
"\t 2.to delete"
"\t 3.to display"
"\t 4.exit\n"
"enter ur choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nenter the element to be inserted :");
scanf("%d",&num);
qinsert(&q,num);
break;
case 2:
num=qdelete(&q);
if(num!=-1)
printf("\n popped element %d",num);
break;
case 3:
qdisplay(q);
break;
case 4:
default:done=1;
break;
}
}
}
No comments:
Post a Comment