#include <iostream>
#define capacity 1000000
using namespace std;
class Stack
{
int * s;
int top;
bool isEmpty ()
{
if (top == -1 || !s)
return true;
return false;
}
bool isFull ()
{
if (top == capacity - 1)
return true;
return false;
}
void pushAtBottom (int);
public:
Stack ()
{
top = -1;
s = new int [capacity];
}
~Stack ()
{
delete s;
}
void push (int);
int pop ();
void reverse ();
void print ();
};
void Stack :: push (int data)
{
if (isFull ())
{
cout << "Error: Stack overflow" << endl;
return;
}
s[++top] = data;
}
int Stack :: pop ()
{
if (isEmpty ())
{
cout << "Stack underflow" << endl;
return -1;
}
return s[top--];
}
void Stack :: reverse ()
{
if (isEmpty ())
return;
int data = pop ();
reverse ();
pushAtBottom (data);
}
void Stack :: pushAtBottom (int data)
{
if (isEmpty ())
{
push (data);
return;
}
int next = pop ();
pushAtBottom (data);
push (next);
}
void Stack :: print ()
{
for (int i = top; i >= 0; i--)
cout << s[i] << " ";
cout << endl;
}
int main (void)
{
Stack s;
s.push (1);
s.push (2);
s.push (3);
s.push (4);
s.push (5);
s.push (6);
s.push (7);
s.print ();
s.reverse ();
s.print ();
return 0;
}