Crx-reverse a stack

In this video instead of using a helper class, we can swap the top and bottom elements which take splace in O(n) time will it be a better solution?
Code:

temp=location(first element)—>O(n)
top=this.top

ref=top;
while(top>temp)
{
t=data[temp]
data[top]=data[temp]
data[temp]=t
top–;
temp++;
}
top=ref;

Will this be a better code becazuse we are not using extra memory right?

This won’t help in reversing the stack. You can check it yourself by printing the elements before and after in your ide. Also, the elements need not to be sorted, they can be randomly placed. So (top>temp) condition is of no use. Did you get it?

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.