데이터의 개수가 n개가 들어오고, n개의 데이터를 거꾸로 출력하는 프로그램을 작성하시오.
#include <iostream>
using namespace std;
enum { eMaxCount = 1001, eInvalid = -1 };
class Stack
{
public:
Stack()
: muTopIndex(0u)
{
}
void Push(int _iData)
{
if (eMaxCount <= muTopIndex)
{
cout << "Stack overflow!" << endl;
return;
}
miarrData[++muTopIndex] = _iData;
}
bool IsEmpty(void)
{
return 0 == muTopIndex;
}
int Top(void)
{
if (true == IsEmpty())
{
cout << "Stack underflow!" << endl;
return eInvalid;
}
return miarrData[muTopIndex];
}
void Pop(void)
{
if (true == IsEmpty())
{
cout << "Stack underflow!" << endl;
return;
}
--muTopIndex;
}
private:
int miarrData[eMaxCount];
unsigned int muTopIndex;
};
int main()
{
int a = 0;
cin >> a;
Stack* StackStorage = new Stack();
for (int i = 0; i < a; i++)
{
int b = 0;
cin >> b;
StackStorage->Push(b);
}
for (int i = 0; i < a; i++)
{
cout << StackStorage->Top() << ' ';
StackStorage->Pop();
}
}