#define N 50
struct queue {
int rear;
int front;
int Q[N];
};
typedef struct queue myqueue;
void makeempty (myqueue *pt)
//create an empty queue
{ pt->rear=N-1;
pt->front=N-1;
}
int isfull (myqueue *pt) //check
whether the queue is full or not
{ int chk;
chk= (pt->rear+1)% N;
if(chk==pt->front)
return(1);
else
return 0;
}
int isempty (myqueue *pt) //check whether the queue is empty or not
{
if(pt->rear == pt->front)
return(1);
else
return 0;
}
void enqueue (myqueue *pt, int item)
//add the item in the queue
{
if(isfull(pt))
printf(“THE QUEUE IS FULL”);
else
{pt->rear= (pt->rear+1) % N
//increment the rear
pt->Q[pt->rear]=item;
//add the item
}
}
int dequeue (myqueue *pt)
//delete an item from the queue
{
int temp;
if(isempty(pt))
printf(“THE QUEUE IS EMPTY”);
else
{pt->front= (pt->front+1) %
N; //increment ‘front’
temp= pt->Q[pt->front];
//store front element in auxiliary variable
return (temp);
}
}
No comments:
Post a Comment