reverse of stack

reverse the order of elements on stack S using one additional stack and some additional nonarray variables

you can pop from one stack and push popped element into second stack. You can get reverse of a stack.

we have to use only additional one stack

yes you can do that by using 1 additional stack ,

//P1 is the stack reverse you want.
//P2 is the reverse of a stack.
int p= P1.pop()

i want reverse of elements in the p1 itself.

for(int i=0;i<10;i++)
int p=;
P1= P2;
Now stack P1

and what about using non array variables while reversing the stack with one additional stack?

here non array variable is variable p

this is a nice explanation of doing that using recursion

thanks! :slight_smile:

using recursion how?

it is explained there in the link i have given