Skip to content

Latest commit

 

History

History
26 lines (24 loc) · 545 Bytes

File metadata and controls

26 lines (24 loc) · 545 Bytes

#SORT STACK (RECURSION) Practice

void insert(stack<int> &s,int temp)
{
    if(s.size()==0 || s.top()<=temp)
    {
        s.push(temp);
        return;
    }
    int ele=s.top();
    s.pop();
    insert(s,temp);
    s.push(ele);
}
void SortedStack :: sort()
{
   if(s.size()==1)
        return;
        
    int temp=s.top();
    s.pop();
    sort();
    insert(s,temp);
}