Reverse Stack Using 1 Extra Stack

Hi sir,

I concern that if we use 1 extra stack to reverse a stack, why don’t we just pop all out from the original stack and push them element by element to the extra stack? Then we just need to print the data of the extra stack.

I don’t know why we have to pop each element and then transfer the rest to the other.

Thanks a lot for your help.

My code for this: http://cpp.sh/8uvd3

Hi , You have to make changes in the original stack only. You cannot print the new stack

Hi @Madeshi-Chinmay-2159857244260221 ,
But I think both approaches take 2 stacks, so they waste the same memory.
What’s the benefit if we try to make changes in the original stack rather than print the new one?

No … the thing is both of your and the original one use 2 stacks but we have to reverse the original stack only and not just print the temporary helper stack . You have to reverse the elements in the original stack only.

Ok, I got it. Thanks a lot