#include "stdlib.h"
#include <stdio.h>
#define int Elemtype
#define MaxSize 50
typedef struct{
Elemtype data[MaxSize];
int top;
} Sqstack;
void Initstack(Sqstack &S){
//初始化栈
S.top=-1;
}
bool StackEmpty(Sqstack S){
//判断栈是否为空
if(S.top==-1) return true;
else return false;
}
bool Push(Sqstack &S,Elemtype x){
if(S.top==MaxSize-1)//栈满报错
return false;
S.data[++S.top]=x; //先栈指针上移然后在赋值
return true;
}
bool Pop(Sqstack &S,Elemtype &x){
//出栈操作
if(S.top==-1) //栈为空
return false;
x=S.data[S.top--]; //先出栈然后指针再减1
return true;
}
bool GetTop(Sqstack S,Elemtype x){
//读栈顶元素
if(S.top==MaxSize-1) //栈为空
return false;
x=S.data[S.top];
return true;
}