GATE IT 2007 · Arrays & Matrix Representation

MCQ · 1 mark · Problem PROG-DSTR-0194

Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:i. isEmpty(Q) returns true if the queue is empty, false otherwise.ii. delete(Q) deletes the element at the front of the queue and returns its value.iii. insert(Q,i) inserts the integer i at the rear of the queue.Consider the following function
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
   i = delete(Q);
   f(Q);
   insert(Q, i);
  }
}
What operation is performed by the above function f ?
  1. A
    Leaves the queue Q unchanged
  2. B
    Reverses the order of the elements in the queue Q
  3. C
    Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order
  4. D
    Empties the queue Q

Solve it on GATE DA practice →More Basic Data Structures problems

Show the worked solutionOfficial GATE Answer Key: Option B.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/3463/gate2007-it-30

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com