#include<bits/stdc++.h>
using namespace std;

void Sort(stack<int>&s){
   
   stack<int>temp;
   while(!s.empty()){
       int data=s.top();
      s.pop();
       while(!temp.empty()&&temp.top()>data){
          s.push(temp.top());
           temp.pop();
       }
       temp.push(data);
   }
   while(!temp.empty()){
        cout<<temp.top()<<endl;
        temp.pop();
    }
}
int main(){
 
    stack<int>arr;
    arr.push(12); arr.push(122); arr.push(14); arr.push(1);  arr.push(-12);
    Sort(arr);
    
}