#include <bits/stdc++.h>
using namespace std;
void rev(stack<int>&x){
	int sz=x.size(),mytop,mybottom;
    mytop=x.top();
    x.pop();
    int tmp[sz-1],i=0;
    while(!x.empty()){
        mybottom=x.top();
        tmp[i++]=mybottom;
        x.pop();
        } 
    stack<int> returnIt;
    returnIt.push(mybottom);
    for(i=0;i<=sz-3;i++){
        returnIt.push(tmp[i]);
        }
    returnIt.push(mytop);
    while(!returnIt.empty()){
    	int tt=returnIt.top();
    	x.push(tt);
    	returnIt.pop();
    }
	}
int main() {
	// your code goes here
	stack<int>x;
	x.push(1);
	x.push(2);
	x.push(3);
	x.push(4);
	x.push(5);
	stack<int>y=x;
	cout<<"Before reversing : ";
	while(!y.empty()){
		int tt=y.top();
		cout<<tt;
		y.pop();
	}
	
	rev(x);
	cout<<"\nAfter reversing : ";
	while(!x.empty()){
		cout<<x.top();
		x.pop();
	}
	return 0;
}