• Source
    1. #include<bits/stdc++.h>
    2. using namespace std;
    3.  
    4. void Sort(stack<int>&s){
    5.  
    6. stack<int>temp;
    7. while(!s.empty()){
    8. int data=s.top();
    9. s.pop();
    10. while(!temp.empty()&&temp.top()>data){
    11. s.push(temp.top());
    12. temp.pop();
    13. }
    14. temp.push(data);
    15. }
    16. while(!temp.empty()){
    17. cout<<temp.top()<<endl;
    18. temp.pop();
    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.  
    27. }