#include<iostream>
#include<stack>
using namespace std;
void reverse(stack<int> &stackA,stack<int> &stackB)
{
int min;
int size=0;
for(int i=0;i<stackA.size();i++)
{
min=stackA.top();
stackA.pop();
while(stackA.size()>size)
{
stackB.push(stackA.top());
stackA.pop();
}
stackA.push(min);
while(!stackB.empty())
{
stackA.push(stackB.top());
stackB.pop();
}
size++;
}
}
int main()
{
stack<int> stackA,stackB;
for(int i=10;i>=0;i--)
{
stackA.push(i);
}
reverse(stackA,stackB);
while(!stackA.empty())
{
cout<<stackA.top()<<" ";
stackA.pop();
}
}
#include<stack>
using namespace std;
void reverse(stack<int> &stackA,stack<int> &stackB)
{
int min;
int size=0;
for(int i=0;i<stackA.size();i++)
{
min=stackA.top();
stackA.pop();
while(stackA.size()>size)
{
stackB.push(stackA.top());
stackA.pop();
}
stackA.push(min);
while(!stackB.empty())
{
stackA.push(stackB.top());
stackB.pop();
}
size++;
}
}
int main()
{
stack<int> stackA,stackB;
for(int i=10;i>=0;i--)
{
stackA.push(i);
}
reverse(stackA,stackB);
while(!stackA.empty())
{
cout<<stackA.top()<<" ";
stackA.pop();
}
}