• Source
    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. void reverse(stack<int>&s,int data1){
    4. if(s.empty()||s.top()<data1){
    5. s.push(data1);
    6. }else{
    7. int data=s.top();
    8. s.pop();
    9. reverse(s,data1);
    10. s.push(data);
    11. }
    12. }
    13. void Sort(stack<int>&s){
    14. if(s.empty())return;
    15. int data=s.top();
    16. s.pop();
    17. Sort(s);
    18. reverse(s,data);
    19.  
    20. }
    21. int main(){
    22.  
    23. stack<int>arr;
    24. arr.push(12); arr.push(122); arr.push(14); arr.push(1); arr.push(-12);
    25. Sort(arr);
    26. while(!arr.empty()){
    27. cout<<arr.top()<<endl;
    28. arr.pop();
    29. }
    30.  
    31. }