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

int main(){
	int n,i,x,y;
	scanf("%d%d%d",&n,&x,&y);
	int a[n+1],b[n+1],who[n+1],howmuch[n+1];
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		}
	for(i=1;i<=n;i++){
		scanf("%d",&b[i]);
		}
	int one=0,two=0;
	vector<pair<int,pair<int ,int> > >vp;
	for(i=1;i<=n;i++){
		//~ if(a[i]>=b[i]){
			//~ who[i]=1;
			//~ one++;
			//~ howmuch[i]=a[i];
			//~ vp.push_back(make_pair(a[i],1));
			//~ }
		//~ else {
			//~ who[i]=2;
			//~ two++;
			//~ howmuch[i]=b[i];
			//~ vp.push_back(make_pair(b[i],2));
			//~ }
		vp.push_back(make_pair(abs(a[i]-b[i]),make_pair(a[i],b[i])));
		}
	int ans=0;
	sort(vp,vp+sizeof(vp));
	for(i=1;i<=n;i++){
		if(vp[i].second.first > vp[i].second.second && x>0){
			x--;
			ans+=vp[i].second.first;
			}
		else if(y>0){
			y--;
			ans+=vp[i].second.second;
			}
		}
	printf("%d",ans);
	return 0;
	}
*/


#include <bits/stdc++.h>
using namespace std;
#define maxi 1001
class Stack
{
public:
    int data[maxi];
    int top,length;
    Stack(int);
    //~Stack();

    void push(int);
    int pop();
    int func();
    void display();
    void Swap(Stack &);
    bool isEmpty();
    bool isFull();
};

Stack::Stack(int size)
{
    top=-1;
    length=size;
}

//Stack::~Stack(){
//    delete [] data;
//}

void Stack::push(int elem)
{
    
    if(top==(length-1))     //If the top reaches to the maximum stack size
    {
        cout<<"\nCannot push "<<elem<<", Stack full"<<endl;
        return;
    }
    else
    {
        //for(int i=0;i<length;i++){
        //cin>>elem;
        top++;
        data[top]=elem;
        //}
    }
}
int Stack::pop()
{
    if(top==-1)
    {
        cout<<"Stack empty!";
        return -1;
    }
    int ret=data[top];
    top--;
    return ret;
}

void Stack::display()
{
    for(int i = 0; i <= top; i++)
        cout<<data[i]<<" ";
    cout<<endl;
}

bool Stack::isEmpty()
{
    if(top==-1){return 1;}
    else return 0;
}
bool Stack::isFull()
{
    if (top==length){return 1;}
    else return 0;
}

void Stack ::Swap(Stack &x){
	int sz=x.length,mytop,mybottom;
    mytop=x.pop();
    int tmp[sz-1],i=0;
    while(!x.isEmpty()){
        mybottom=x.pop();
        tmp[i++]=mybottom;
        }
    Stack returnIt(sz);
    returnIt.push(mybottom);
    for(i=0;i<=sz-3;i++){
        returnIt.push(tmp[i]);
        }
    returnIt.push(mytop);
    x.length=sz;
    x.top=-1;
    while(!returnIt.isEmpty()){
    	int tt=returnIt.pop();
    	x.push(tt);
    }
	}
int main()
{
	int len;
    cout<<"Enter length of stack : ";
    cin>>len;
    Stack s1(len);
    for(int i=0;i<len;i++){
		int element;
		cout<<"Enter element to push into stack : ";
		cin>>element;
		s1.push(element);
		}
    //s1.push(1);
    //s1.push(2);
    //s1.push(3);
    //s1.push(4);
    //s1.push(5);
    //s1.push(6);
    //s1.push(7);
    //s1.push(8);
    //s1.push(9);
    cout<<"\nStack before swapping : ";
    s1.display();
    s1.Swap(s1);
    cout<<"\nStack after swapping : ";
    s1.display();
}
