Computer Science, asked by deepikaepik, 1 month ago

which of the given statements would you use to insert an element in the queue 'q' ?
struct queue{
int data {100};
int front=0, rear= -1;
}q;​

Answers

Answered by anshumanprajapati200
9

Answer:

q.data[q.rear++]=X;

Explanation:

Answered by ankhidassarma9
3

Answer:

Ignoring the possibilities of overflow ,

the statement for the insertion of a node x is as follows:

q.data[++q.rear ]=x;

Explanation:

  • rear always point to the element at the rear(last) position in a queue.
  • Before entering the node , the rear should be incremented by one so that it can refer the next available position in the queue where a new node ca e inserted. ++q.rear is performing the same task.
  • The following function can be used to insert a node which includes checking for the overflow also:    

    void insert ( struct queue *pq, int x)

    {

    If(pq->rear==-1)

   pq-> rear = 0;

 else

  (pq->rear ++);

   if(pq->rear == pq->front)   /* checking for overflow */

     {

  printf("Queue overflow");

   exit(1);

    }

    pq->data[pq-> rear] = x;

    return;

}

Similar questions