#include <iostream>
#include <stack>
#include <cstdlib>

using namespace std;

void reverse_stack(stack<int>&);
void add_to_bottom(stack<int>&, int);

void reverse_stack(stack<int> &istack) {
  if(!istack.empty()) {
    int top = istack.top();
    istack.pop();

    reverse_stack(istack);
    add_to_bottom(istack, top);
  }
}

void add_to_bottom(stack<int> &istack, int val) {
  if(istack.empty()) {
    istack.push(val);
  } else {
    int top = istack.top();
    istack.pop();

    add_to_bottom(istack, val);
    istack.push(top);
  }
}

int main(int argc, char **argv) {

  stack<int> istack;
  for(int i=0; i<10; i++) {
    int tmp = rand()%100;
    istack.push(tmp);
    cout << tmp << " ";
  }
  cout << endl;

  reverse_stack(istack);

  while(!istack.empty()) {
  int top = istack.top();
  cout << top << " ";
  istack.pop();
  }
  cout << endl;

  return 0;
}
