Q:

swapping the first and last element in a stack using c++

i want to make a function to take a stack (as array)
and for it to return the stack swapping the first element with the last element in the Stack
so i'll use a temp stack for the data
and i'll use 
but how will i know when will i reach the end of the stack ?
i've wrote the implementation of stack as an array 
but i need help with the function swap
void Swap(Stack x)
{
Stack tmp(100);
int top1 = x.pop;

for (int i = 0;; i++)
{
x.pop = tmp.push;
}

}

i know its wrong but i'm not sure 
any help would be appreciated 
,thanks 
Edit
i wrote the function at first this way and found i can't take the parameters 
void stack::Swap()
{
Stack tmp(100);
int top1 =  this->pop;

for (int i = 0;; i++)
{
this->pop = tmp.push
}

};

Edit here is a code from an answer 
Stack Swap(Stack x){

int mytop,mybottom;

mytop=x.pop();

int tmp[x.length-2],i=0;

while(!x.isEmpty()){

    mybottom=x.pop();

    tmp[i++]=mybottom;

    }

Stack returnIt;

returnIt.push(mytop);

for(i=0;i<=x.length -3;i++){

    returnIt.push(tmp[i]);

    }

returnIt.push(mybottom);

return returnIt;

}

A:

IDEA : Store top and bottom of stack in a variable and elements between top and bottom in an array. Now you just push bottom of original stack into new stack and than elements in original order and than finally the top of original stack. 
code.
#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;
}

