can you edit and tell why it’s not working ?
No output : implement q using 2 stks
Hey @premang
Did some changes and mentioned them in comments ,please have a look : https://ide.codingblocks.com/s/320651
Its still not working because u don’t have to swap stacks ,instead u have to empty the second stack again into 1st stack
Say we have (1,2,3) () as stacks where Right end is top
so if we pop we will be doing this (1,2)(3) -> (1)(3,2) ->()(3,2) ->(2)(3)->(2,3)()
But right now when you are swapping you are doing this
(1,2)(3) -> (1)(3,2) ->()(3,2) ->(3,2)()
u see at end in swapping order of elements is reversed.
So basically you have to remove swap function and replace them by moving_back_to_stack1 function
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.