#include <iostream>
                    #include <stack>
                    using namespace std;
                    void insert(stack<int>&s,int val){
                      if(s.empty()){
                        s.push(val);
                        return;
                      }
                      int temp=s.top();
                      s.pop();
                      insert(s,val);
                      s.push(temp);
                    }
                    int main(){
                      stack<int>s;
                      s.push(10);
                      s.push(20);
                      s.push(30);
                      s.push(40);
                      insert(s,5);
                      while(!s.empty()){
                        cout<<s.top()<<" ";
                        s.pop();
                      }
                      cout<<endl;
                      return 0;
                    }