Problem Solving – You are using the following algorithm to implement a queue by reusing two stacks…


You are using the following algorithm to implement a queue by reusing two stacks.

A(q, x)

1) Push x to stack1

B(q)

1) If both stacks are empty then error.

2) If stack2 is empty

While stack1 is not empty, X

3) Pop the element from stack2 and return it.

What can be used in place of X to complete the algorithm?

[Assume that the size of stacks is unlimited.]


Related Posts

Close Bitnami banner
Bitnami