You are given two stacks with the element 1,2,3,4,5, which must be placed in the same sequence in both stacks. Once an element is added to a stack, it can only be popped and displayed (but it cannot be pushed onto the other stack again). So the possible actions are s.pop(), s.push(), and s.top() (to return the stack's top element), and the method display(int) outputs an integer result. Both stacks have access to these three operations. If it is not empty, you can do a pop operation whenever you want. Which of the following sequences cannot be produced with the aforementioned constraints?

1
3 1 2 4 5
2
4 1 5 2 3
3
4 2 1 3 5
4
5 4 3 2 1

Sponsored

hivanix.in

Visit

This quiz is brought to you by hivanix.in

🌐 Web App Development

Quick Navigation