Consider implementation of stack using queue by following algorithm. Let x be…

Consider implementation of stack using queue by following algorithm. Let x be an element to be pushed in the stack.

push(q1, x) {

EQ(q1,x)

size = q1.size();

while (size > 1) {

k= DQ(q1)

EQ(q1,k)

Size--;

}

}

pop(q1) {

DQ(q1)

}

How many enqueue and dequeue operations required to perform 3 push and 1 pop sequentially in an empty stack?

  1. A.

    6EQ, 3DQ

  2. B.

    5EQ, 5DQ

  3. C.

    4EQ, 2DQ

  4. D.

    6EQ, 4DQ

Attempted by 289 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…