can you please tell me how this function work
void reverse(stack &st) //passed by ref as to reflect change in main
{
if(st.empty())
{
return;
}
else
{
int x=st.top();
st.pop();
reverse(st);
insert(st,x);
}
}
can you please tell me how this function work
void reverse(stack &st) //passed by ref as to reflect change in main
{
if(st.empty())
{
return;
}
else
{
int x=st.top();
st.pop();
reverse(st);
insert(st,x);
}
}
Hello @Ankit_123,
To understand the solution to this problem.
You need to understand the operation of the insert function also.
reverse() function:
insert() function: To insert the element x at the bottom of the stack st.
Hope, this would help.
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.