#include<iostream>
using namespace std;
const int MaxSize = 10;
class Stack
{public:
Stack();
void Push(int x);
int Pop();
int GetTop();
private:
int data[MaxSize];
int top;
};
Stack::Stack()
{
top = -1;
}
void Stack::Push(int x)
{
if (top == MaxSize - 1)throw"上溢";
else
{
data[++top] = x;
}
}
int Stack::Pop()
{
if (top == -1)throw"下溢";
else
{
return data[top--];
}
}
int Stack::GetTop()
{
if (top == -1)throw"下溢";
else
{
return data[top];
}
}
int main()
{
Stack s;
cout << "对5和8进行入栈" << endl;
s.Push(5);
s.Push(8);
cout << s.GetTop() << endl;
cout << s.Pop() << endl;
cout << s.GetTop() << endl;
}