edited by
893 views
0 votes
0 votes

Suppose you are given an implementation of a queue of integers. The operations that can be performed on
the queue are:
1. is_empty (Q): return true if the queue is empty, false otherwise.
2. delete (Q): deletes the elements at the front of the queue and return its value.
3. insert (Q, i): inserts the integer i at the rear of the queues.
Consider the following function:
void f(Queue Q)
{
int i;
if (! is empty ( ) )
{
_______
}
}
The following function must perform the operation that it must reverse the elements of queue (Q). Which of
the following options can be filled in the blank to perform the above operation.

f(Q)

insert(Q,i)

a.i=delete(Q)

f(Q)

b.insert(Q,i)

i=delete(Q)

insert(Q,i)

f(Q)

c.f(Q)

i=delete(Q)

insert(Q,i)

d.none of these.

edited by

1 Answer

0 votes
0 votes
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
}

This is the right approach to reverse the queue. All options are wrong.

BECAUSE NO WONDER ITS MADE EASY !!!!

No related questions found