void reversestack(stack &s1){
int n = s1.size() ;
stack <int> s2 ;
while(n--)
{
int x = s1.top();
s1.pop();
while(s1.size()){
s2.push(s1.top());
s1.pop();
}
s1.push(x);
while(s2.size()){
s1.push(s2.top());
s2.pop();
}
}
}
why this code doesn’t give the desired output of reversing a stack?