Queue Operations

 Queue Operations are......

         Enqueue—Add an item(new item in back side) to the end of the queue.

         Dequeue—Remove an item from the front.

         Queue Front—Who is first?

         Queueu End—Who is last?

 

 

 

 

 

1)Storage for a queue…..

Struct intqueue

  {

            int *queueAry;

            int maxSize;

           int countt;

           int frontt;

           int rearr;  

};

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;

    }

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*/              

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*/              

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*/

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*/

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*/

8)  destroyQueue……

struct intqueue *destroyQueue(struct intqueue *queuee)

    {

           /*statements*/

           if(queuee)

              {

                 free(queuee->queueAry);

                 free(queuee);

              }/* if end*/

      return NULL;

   }/*destroyQueue end*/

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @