Q. Consider an empty stack of integers. Let the numbers 1, 2, 3, 4, 5, 6 be pushed on to this stack only in the order they appeared from left to right. Let S indicates a push and X indicates a pop operation. Can they be outputted in to the order 325641 and order 154623 ?
(Hint. SSSSSSXXXXXX outputs 654321)
Answer :-
SSSXXSSXSXXX outputs 325641.
154623 cannot be output as 2 is pushed much before 3 so can appear only after 3 in output.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )