Queue Operations are……
1· Enqueue—Add an item(new item in the backside) to the end of the queue.
2· Dequeue—Remove an item from the front.
3· Queue Front—Who is first?
4· Queueu End—Who is last?
What is the Queue algorithm in the C data structure?
1)Storage for a queue…..
Struct intqueue
{
int *queueAry;
int maxSize;
int countt;
int frontt;
int rearr;
};
What is the algorithm of Createqueue?
2)Create Queue………
struct intqueue *createQueue(int maxSize)
{
struct intqueue *queuee;
queuee=(struct intqueue *)malloc(sizeof(struct intqueue));//head structure created
if(queuee!=NULL)
{
queuee->queueAry=(int *)malloc(maxSize *sizeof(int)); /* allocate queue*/
queuee->frontt=-1;
queuee->rearr=-1;
queuee->countt=0;
queuee->maxSize=maxSize;
}
return queuee;
}
What is the algorithm of Enqueue?
3)Enqueue…..
int enqueue(struct intqueue *queuee,int *dataIn)
{
if(!queuee->countt==queuee->maxSize)
return 0;
(queuee->rearr)++;
if(queuee->rearr==queuee->maxSize)
/* queue wraps to element 0*/
queuee->rearr=0;
queuee->queueAry[queuee->rearr]=datain;
if(queuee->countt==0)
{
/* inserting into null queue*/
queuee->frontt=0;
queuee->countt=1;
} //end if
else(queuee->countt)++;
return 1;
} /*enqueue end*/
What is the algorithm of Dequeue?
4)Dequeue……
int dequeue(struct intqueue *queuee,int *dataOutPtr)
{
if(!queuee->countt)
return 0;
*dataOutPtr=queuee->queuee->queueAry[queuee->frontt];
(queuee->frontt)++;
if(queuee->frontt==queuee->maxSize)
/* queue front has wrapped to element 0*/
queuee->frontt=0;
if(queuee->countt==1)
/* deleted only item in queue*/
queuee->rearr=queuee->frontt=-1;
(queuee->countt)–;
return 0;
} /*dequeue end*/
What is the algorithm of queueFront?
5) queueFront……
int queueFront(struct intqueue *queuee,int *dataOutPtr)
{
if(!queuee->countt)
return 0;
else
{
*dataOutPtr=queuee->queueAry[queuee->frontt];
return 1;
} /*else end*/
}/* queue front end*/
What is the algorithm of queueRear?
6)queueRear………
int queueRear(struct intqueue *queuee,int *dataOutPtr)
{
if(!queuee->countt)
return 0;
else
{
*dataOutPtr=queuee->queueAry[queuee->rearr];
return 1;
} /*else end*/
}/* queue rear end*/
What is the algorithm for empty queues and full Queues?
7) emptyQueue and fullQueue……..
int emptyQueue(struct intqueue *queuee)
{
/*statements*/
return(queuee->countt==0);
} /*empty queue*/
int fullQueue(struct intqueue *queuee)
{
return(queuee->countt==queuee->maxSize);
} /*full queue*/
What is the algorithm for destroying a queue?
8) destroyQueue……
struct intqueue *destroyQueue(struct intqueue *queuee)
{
/*statements*/
if(queuee)
{
free(queuee->queueAry);
free(queuee);
}/* if end*/
return NULL;
}/*destroyQueue end*/