π One-stop destination for all your technical interview Preparation π
Insert function.
Sort function.
void inserT(stack<int> &s, int temp)
{
if (s.empty() || s.top() <= temp)
{
s.push(temp);
return;
}
int val = s.top();
s.pop();
inserT(s, temp);
s.push(val);
}
void sortStack(stack<int> &s)
{
if (s.size() == 1)
return;
int temp = s.top();
s.pop();
sortStack(s);
inserT(s, temp);
}