Suppose you are given an implementation of a queue of integers. Consider the…

GATE · 2007 · IT

Suppose you are given an implementation of a queue of integers.

Queue operation definitions: isEmpty(Q) reports whether Q is empty; delete(Q) removes and returns the front element; insert(Q, i) inserts i at the rear.

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

Attempted by 736 students.

Show answer

Correct answer: B

The worked solution is available to enrolled students.

Video solution available to enrolled students.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…