A stack is implemented using queue(s); q1 is the queue that stores the stack's…

A stack is implemented using queue(s); q1 is the queue that stores the stack's elements. The Java method below is one of the operations of that stack.

public void fun(int x) {
q1.offer(x);
}

Which stack operation does this method perform, and in this implementation which operation - push() or pop() - is the costlier one?

  1. A.

    Perform push() with push as the costlier operation

  2. B.

    Perform push() with pop as the costlier operation

  3. C.

    Perform pop() with push as the costlier operation

  4. D.

    More than one of the above

  5. E.

    None of the above

Attempted by 17 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…