#include <iostream>
using namespace std;
#define maxlength 100
typedef int Elementtype;
struct STACK
{
int top;
Elementtype elements[maxlength];
};
//以数组最大段(下标)为栈底,top依次上升
void MakeNull(STACK *S)//MakeNull
{
S->top = maxlength;
}
bool Empty(STACK *S)//测试栈S是否为空
{
if(S->top > maxlength - 1)
return true;
else
return false;
}
Elementtype Top(STACK *S)//返回栈S的栈顶元素
{
if( Empty(S) )
cout << "Stack is empty!" << endl;
else
return (S->elements[S->top]);
}
void Pop(STACK *S)//删除栈S的栈顶元素
{
if( Empty(S) )
cout<<"Stack is empty!"<<endl;
else
S->top = S->top + 1;
}
void Push(Elementtype x,STACK *S)//将元素x压入栈S的栈顶
{
if(S->top == 0)
cout << "Stack is full!" << endl;
else
{
S->top = S->top - 1;
S->elements[S->top] = x;
}
}
int main()
{
STACK *S;
int m;
MakeNull(S);
Push(12,S);
m=Top(S);
cout << m << endl;
return 0;
}