Which of the following permutations can be obtained in the output using a stack of size 3 elements assuming that input, sequence is 1, 2, 3, 4, 5?
A. 3, 2, 1, 5, 4
B. 5, 4, 3, 2, 1
C. 3, 4, 5, 2, 1
D. 3, 4, 5, 1, 2
Answer:A
Which of the following permutations can be obtained in the output using a stack of size 3 elements assuming that input, sequence is 1, 2, 3, 4, 5?
A. 3, 2, 1, 5, 4 B. 5, 4, 3, 2, 1 C. 3, 4, 5, 2, 1 D. 3, 4, 5, 1, 2
Explanation: Initially 1, 2, 3 are pushed into stack after that if you want to push 4 in stack then pop 3 then push 4. If you want to push 5 then pop 4 and push 5. After that elements are poped from stack are 5, 2, 1.