//顺序栈的操作
#include<iostream>
using namespace std;
typedef int ElemType;
#define MAX 100
typedef struct Node
{
ElemType data[MAX];
int top;
}SeqStack;
void InitStack(SeqStack *s)
{
s->top = -1;
}
int IsEmpty(SeqStack *s)
{
return (s->top == -1)?1:0;
}
void Push(SeqStack *s,ElemType x)
{
if(s->top == MAX-1)
{
cout<<"栈满!"<<endl;
return;
}
s->data[++s->top] = x;
}
void Pop(SeqStack *s)
{
if(IsEmpty(s))
{
cout<<"栈为空!"<<endl;
return;
}
s->top--;
}
int GetTop(SeqStack *s,ElemType *x)
{
if(IsEmpty(s))
{
cout<<"栈为空!"<<endl;
return 0;
}
*x = s->data[s->top];
return 1;
}
int main()
{
SeqStack *s = (SeqStack*)malloc(sizeof(SeqStack));
InitStack(s);
for(int i = 0; i<5; i++)
Push(s,i);
ElemType e;
GetTop(s,&e);
cout<<e<<endl;
return 1;
}